Add Tack Shop Giveaways

This commit is contained in:
SilicaAndPina 2021-03-31 19:59:14 +13:00
parent 5cac72f67a
commit 2e4ba0b82d
5 changed files with 195 additions and 6 deletions

View file

@ -67,7 +67,13 @@
"event_end":"<B>TIME IS UP:</B> No one answered the Chat Riddle in time.",
"event_won_others":"<B>RIDDLE SOLVED!</B> By player %PLAYERNAME%!",
"event_won_you":"<B>YOU SOLVED THE RIDDLE!</B> You earned: $%PRIZE%!"
}
},
"tack_shop_giveaway":{
"event_start":"<B>TACK SHOP HORSE GIVEAWAY:</B> A %COLOR% %BREED% %GENDER% will be given away to one random person at %SHOPNAME% in %TOWN% in 2 minutes!!!",
"event_1min":"<B>TACK SHOP HORSE GIVEAWAY:</B> A %COLOR% %BREED% %GENDER% will be given away to one random person at %SHOPNAME% in %TOWN% in 1 minute!!!",
"event_won":"<B>TACK SHOP HORSE GIVEAWAY:</B> %PLAYERNAME% has won the %BREED% horse Giveaway at %SHOPNAME% in %TOWN%! Thanks to all %PLAYERCOUNT% players that attended the event.",
"event_end":"<B>TACK SHOP HORSE GIVEAWAY:</B> No one was at %SHOPNAME% in %TOWN% to win the horse. Oh well, event is over.",
},
},
"horse_leaser":{
"cant_afford":"You cannot afford the lease fee.",

View file

@ -0,0 +1,149 @@
using HISP.Game.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using HISP.Server;
using HISP.Game.Horse;
using System.Threading;
using HISP.Player;
namespace HISP.Game.Events
{
public class TackShopGiveaway
{
public string ShopName;
public World.SpecialTile Location;
public HorseInstance HorseGiveaway;
public World.Town Town;
public bool Active = false;
public const int TACKSHOP_TIMEOUT = 1;
private Timer giveAwayTimer;
private int timesTicked = 0;
private void giveawayTick(object state)
{
timesTicked++;
if (timesTicked >= 2)
{
EndEvent();
return;
}
if (timesTicked >= 1)
{
byte[] giveAwayMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveaway1Min(HorseGiveaway.Color, HorseGiveaway.Breed.Name, HorseGiveaway.Gender, ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(giveAwayMessage);
}
giveAwayTimer.Change(TACKSHOP_TIMEOUT * 60 * 1000, TACKSHOP_TIMEOUT * 60 * 1000);
}
public TackShopGiveaway()
{
List<World.SpecialTile> specialTiles = new List<World.SpecialTile>();
foreach(World.SpecialTile sTile in World.SpecialTiles)
{
if(sTile.Code != null)
{
if(sTile.Code.StartsWith("STORE-"))
{
int storeId = int.Parse(sTile.Code.Split("-")[1]);
Shop shopData = Shop.GetShopById(storeId);
if(shopData.BuysItemTypes.Contains("TACK"))
{
Npc.NpcEntry[] npcShop = Npc.GetNpcByXAndY(sTile.X, sTile.Y);
if(npcShop.Length > 0)
{
if(npcShop[0].ShortDescription.ToLower().Contains("tack"))
{
specialTiles.Add(sTile);
}
}
}
}
}
}
string npcName = "ERROR";
string npcDesc = "OBTAINING NAME";
int shpIdx = GameServer.RandomNumberGenerator.Next(0, specialTiles.Count);
Location = specialTiles[shpIdx];
Npc.NpcEntry[] npcShops = Npc.GetNpcByXAndY(Location.X, Location.Y);
npcName = npcShops[0].Name.Split(" ")[0];
npcDesc = npcShops[0].ShortDescription.Substring(npcShops[0].ShortDescription.ToLower().IndexOf("tack"));
ShopName = npcName + "'s " + npcDesc;
while(true)
{
int hrsIdx = GameServer.RandomNumberGenerator.Next(0, HorseInfo.Breeds.Count);
HorseInfo.Breed breed = HorseInfo.Breeds[hrsIdx];
if (breed.SpawnInArea == "none")
continue;
HorseGiveaway = new HorseInstance(breed);
HorseGiveaway.Name = "Tack Shop Giveaway";
break;
}
if (World.InTown(Location.X, Location.Y))
Town = World.GetTown(Location.X, Location.Y);
}
public void StartEvent()
{
giveAwayTimer = new Timer(new TimerCallback(giveawayTick), null, TACKSHOP_TIMEOUT * 60 * 1000, TACKSHOP_TIMEOUT * 60 * 1000);
byte[] giveAwayMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayStart(HorseGiveaway.Color, HorseGiveaway.Breed.Name, HorseGiveaway.Gender, ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(giveAwayMessage);
Active = true;
GameServer.TackShopGiveawayEvent = this;
}
public void EndEvent()
{
giveAwayTimer.Dispose();
Active = false;
GameServer.TackShopGiveawayEvent = null;
User[] usersHere = GameServer.GetUsersAt(Location.X, Location.Y, false, true);
if(usersHere.Length > 0)
{
int winIndx = GameServer.RandomNumberGenerator.Next(0, usersHere.Length);
User winner = usersHere[winIndx];
winner.HorseInventory.AddHorse(HorseGiveaway);
byte[] horseWonMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayWon(winner.Username, HorseGiveaway.Breed.Name, ShopName, Town.Name, usersHere.Length), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(horseWonMessage);
}
else
{
byte[] eventEndedMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayEnd(ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(eventEndedMessage);
}
}
}
}

View file

@ -64,6 +64,12 @@ namespace HISP.Game
public static string EventWonRealTimeRiddleForOthersFormat;
public static string EventWonRealTimeRiddleForYouFormat;
// Events : Tack Shop Giveaway
public static string EventStartTackShopGiveawayFormat;
public static string Event1MinTackShopGiveawayFormat;
public static string EventWonTackShopGiveawayFormat;
public static string EventEndTackShopGiveawayFormat;
// MultiHorses
public static string OtherPlayersHere;
public static string MultiHorseSelectOneToJoinWith;
@ -1101,6 +1107,25 @@ namespace HISP.Game
// Click
public static string NothingInterestingHere;
// Event : Tack Shop Giveaway
public static string FormatEventTackShopGiveawayEnd(string shopName, string townName)
{
return EventEndTackShopGiveawayFormat.Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName);
}
public static string FormatEventTackShopGiveawayWon(string playerName, string breed, string shopName, string townName, int totalPlayersAt)
{
return EventWonTackShopGiveawayFormat.Replace("%PLAYERNAME%", playerName).Replace("%BREED%", breed).Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName).Replace("%PLAYERCOUNT%", totalPlayersAt.ToString("N0", CultureInfo.InvariantCulture));
}
public static string FormatEventTackShopGiveaway1Min(string color, string breed, string gender, string shopName, string townName)
{
return Event1MinTackShopGiveawayFormat.Replace("%COLOR%", color).Replace("%BREED%", breed).Replace("%GENDER%", gender).Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName);
}
public static string FormatEventTackShopGiveawayStart(string color, string breed, string gender, string shopName, string townName)
{
return EventStartTackShopGiveawayFormat.Replace("%COLOR%", color).Replace("%BREED%", breed).Replace("%GENDER%", gender).Replace("%SHOPNAME%", shopName).Replace("%TOWN%", townName);
}
// Event : Real Time Riddle
public static string FormatEventRealTimeRiddleStart(string riddleText)
{

View file

@ -924,6 +924,14 @@ namespace HISP.Server
Messages.EventWonRealTimeRiddleForOthersFormat = gameData.messages.events.real_time_riddle.event_won_others;
Messages.EventWonRealTimeRiddleForYouFormat = gameData.messages.events.real_time_riddle.event_won_you;
// Events : Tack Shop Giveaway
Messages.EventStartTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_start;
Messages.Event1MinTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_1min;
Messages.EventWonTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_won;
Messages.EventEndTackShopGiveawayFormat = gameData.messages.events.tack_shop_giveaway.event_end;
// MultiHorses
Messages.OtherPlayersHere = gameData.messages.meta.multihorses.other_players_here;
Messages.MultiHorseSelectOneToJoinWith = gameData.messages.meta.multihorses.select_a_horse;

View file

@ -40,6 +40,7 @@ namespace HISP.Server
// Events
public static RealTimeRiddle RiddleEvent = RealTimeRiddle.GetRandomRiddle();
public static TackShopGiveaway TackShopGiveawayEvent;
/*
* Private stuff
@ -143,7 +144,11 @@ namespace HISP.Server
}
}
}
if(totalMinutesElapsed % (60 * 3) == 0)
{
TackShopGiveawayEvent = new TackShopGiveaway();
TackShopGiveawayEvent.StartEvent();
}
if(totalMinutesElapsed % 30 == 0)
{
RiddleEvent = RealTimeRiddle.GetRandomRiddle();
@ -195,10 +200,6 @@ namespace HISP.Server
}
}
if (RandomNumberGenerator.Next(0, 100) == 59) // Real Time Riddle
{
}
Database.IncPlayerTirednessForOfflineUsers();