Remove " " space from the names

This commit is contained in:
AtelierWindows 2021-01-28 20:56:27 +13:00
parent bef3032886
commit 8e451633dc
59 changed files with 391 additions and 391 deletions

View file

@ -0,0 +1,47 @@
using System.Collections.Generic;
namespace HISP.Game
{
class AbuseReport
{
public struct ReportReason
{
public string Id;
public string Name;
public string Meta;
}
private static List<ReportReason> reportReasons = new List<ReportReason>();
public static ReportReason[] ReportReasons
{
get
{
return reportReasons.ToArray();
}
}
public static bool DoesReasonExist(string id)
{
try
{
GetReasonById(id);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public static ReportReason GetReasonById(string id)
{
foreach(ReportReason reason in ReportReasons)
{
if (reason.Id == id)
return reason;
}
throw new KeyNotFoundException("No reason of: " + id + " Found.");
}
public static void AddReason(ReportReason reason)
{
reportReasons.Add(reason);
}
}
}

View file

@ -0,0 +1,477 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HISP.Player;
using HISP.Server;
namespace HISP.Game.Chat
{
class Chat
{
public struct Correction
{
public string FilteredWord;
public string ReplacedWord;
}
public struct Reason
{
public string Name;
public string Message;
}
public struct Filter
{
public string FilteredWord;
public Reason Reason;
public bool MatchAll;
}
public enum ChatChannel
{
All = 0x14,
Ads = 0x1D,
Near = 0x15,
Buddies = 0x17,
Here = 0x18,
Isle = 0x1A,
Dm = 0x16,
Mod = 0x1c,
Admin = 0x1b
}
public static string PrivateMessageSound;
public static List<Filter> FilteredWords = new List<Filter>();
public static List<Correction> CorrectedWords = new List<Correction>();
public static List<Reason> Reasons = new List<Reason>();
public static bool ProcessCommand(User user, string message)
{
if (message.Length < 1)
return false;
string[] args = message.Split(' ').Skip(1).ToArray();
if (user.Administrator || user.Moderator)
if (message[0] == '%')
{
if(message.StartsWith("%STICKBUG"))
return Command.Stickbug(message, args, user);
if (message.StartsWith("%GIVE"))
return Command.Give(message, args, user);
if (message.StartsWith("%GOTO"))
return Command.Goto(message, args, user);
if (message.StartsWith("%KICK"))
return Command.Kick(message, args, user);
if (message.StartsWith("%NOCLIP"))
return Command.NoClip(message, args, user);
return false;
}
if (message[0] == '!')
{
// Alias for !MUTE
if (message.StartsWith("!MUTEALL"))
return Command.Mute(message, new string[] { "ALL" }, user);
else if (message.StartsWith("!MUTEADS"))
return Command.Mute(message, new string[] { "ADS" }, user);
else if (message.StartsWith("!MUTEGLOBAL"))
return Command.Mute(message, new string[] { "GLOBAL" }, user);
else if (message.StartsWith("!MUTEISLAND"))
return Command.Mute(message, new string[] { "ISLAND" }, user);
else if (message.StartsWith("!MUTENEAR"))
return Command.Mute(message, new string[] { "NEAR" }, user);
else if (message.StartsWith("!MUTEHERE"))
return Command.Mute(message, new string[] { "HERE" }, user);
else if (message.StartsWith("!MUTEBUDDY"))
return Command.Mute(message, new string[] { "BUDDY" }, user);
else if (message.StartsWith("!MUTEPM"))
return Command.Mute(message, new string[] { "PM" }, user);
else if (message.StartsWith("!MUTEPM"))
return Command.Mute(message, new string[] { "PM" }, user);
else if (message.StartsWith("!MUTEBR"))
return Command.Mute(message, new string[] { "BR" }, user);
else if (message.StartsWith("!MUTESOCIALS"))
return Command.Mute(message, new string[] { "SOCIALS" }, user);
else if (message.StartsWith("!MUTELOGINS"))
return Command.Mute(message, new string[] { "LOGINS" }, user);
else if (message.StartsWith("!MUTE"))
return Command.Mute(message, args, user);
}
return false;
}
public static Object FilterMessage(string message) // Handles chat filtering and violation stuffs returns
{
if (!ConfigReader.BadWords) // Freedom of Speech Mode
return null;
string[] wordsSaid;
if (message.Contains(' '))
wordsSaid = message.Split(' ');
else
wordsSaid = new string[] { message };
foreach(Filter filter in FilteredWords)
{
if (!filter.MatchAll)
{
foreach (string word in wordsSaid)
{
if (word.ToLower() == filter.FilteredWord.ToLower())
return filter.Reason;
}
}
else
{
if (message.ToLower().Contains(filter.FilteredWord))
return filter.Reason;
}
}
return null;
}
public static byte GetSide(ChatChannel channel)
{
switch (channel)
{
case ChatChannel.All:
case ChatChannel.Ads:
case ChatChannel.Isle:
return PacketBuilder.CHAT_BOTTOM_LEFT;
case ChatChannel.Buddies:
case ChatChannel.Here:
case ChatChannel.Admin:
case ChatChannel.Mod:
return PacketBuilder.CHAT_BOTTOM_RIGHT;
case ChatChannel.Dm:
return PacketBuilder.CHAT_DM_RIGHT;
default:
Logger.ErrorPrint("unknown channel: " + (byte)channel);
return PacketBuilder.CHAT_BOTTOM_LEFT;
}
}
public static string GetDmRecipiant(string message)
{
if(message.Contains('|'))
{
string recipiantName = message.Split('|')[0];
return recipiantName;
}
else
{
return null;
}
}
public static string GetDmMessage(string message)
{
if (message.Contains('|'))
{
string messageStr = message.Split('|')[1];
return messageStr;
}
else
{
return message;
}
}
public static GameClient[] GetRecipiants(User user, ChatChannel channel, string to=null)
{
if (channel == ChatChannel.All)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MuteGlobal && !client.LoggedinUser.MuteAll)
if (client.LoggedinUser.Id != user.Id)
recipiants.Add(client);
}
return recipiants.ToArray();
}
if(channel == ChatChannel.Ads)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MuteAds && !client.LoggedinUser.MuteAll)
if (client.LoggedinUser.Id != user.Id)
recipiants.Add(client);
}
return recipiants.ToArray();
}
if(channel == ChatChannel.Buddies)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MuteBuddy && !client.LoggedinUser.MuteAll)
if (client.LoggedinUser.Id != user.Id)
if (client.LoggedinUser.Friends.List.Contains(user.Id))
recipiants.Add(client);
}
return recipiants.ToArray();
}
if (channel == ChatChannel.Isle)
{
List<GameClient> recipiants = new List<GameClient>();
if(World.InIsle(user.X,user.Y))
{
User[] usersInSile = GameServer.GetUsersUsersInIsle(World.GetIsle(user.X, user.Y), true, false);
foreach (User userInIsle in usersInSile)
{
if (user.Id != userInIsle.Id)
if(!user.MuteAll)
recipiants.Add(userInIsle.LoggedinClient);
}
return recipiants.ToArray();
}
else
{
return new GameClient[0];
}
}
if (channel == ChatChannel.Here)
{
List<GameClient> recipiants = new List<GameClient>();
User[] usersHere = GameServer.GetUsersAt(user.X, user.Y, true, false);
foreach (User userHere in usersHere)
{
if (user.Id != userHere.Id)
if (!user.MuteAll)
recipiants.Add(userHere.LoggedinClient);
}
return recipiants.ToArray();
}
if (channel == ChatChannel.Near)
{
List<GameClient> recipiants = new List<GameClient>();
User[] nearbyUsers = GameServer.GetNearbyUsers(user.X, user.Y, true, false);
foreach (User nearbyUser in nearbyUsers)
{
if (user.Id != nearbyUser.Id)
if (!user.MuteAll)
recipiants.Add(nearbyUser.LoggedinClient);
}
return recipiants.ToArray();
}
if (channel == ChatChannel.Mod)
{
if (!user.Moderator || !user.Administrator) // No mod chat for non-mods!
{
Logger.WarnPrint(user.Username + " attempted to send in MOD chat, without being a MOD.");
return new GameClient[0];
}
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Moderator)
if (client.LoggedinUser.Id != user.Id)
recipiants.Add(client);
}
return recipiants.ToArray();
}
if(channel == ChatChannel.Admin)
{
if (!user.Administrator) // No admin chat for non-admins!
{
Logger.WarnPrint(user.Username + " attempted to send in ADMIN chat, without being an ADMIN.");
return new GameClient[0];
}
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Administrator)
if (client.LoggedinUser.Id != user.Id)
recipiants.Add(client);
}
return recipiants.ToArray();
}
if(channel == ChatChannel.Dm)
{
if (to != null)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MutePrivateMessage && !client.LoggedinUser.MuteAll)
if (client.LoggedinUser.Username == to)
recipiants.Add(client);
}
return recipiants.ToArray();
}
else
{
Logger.ErrorPrint("Channel is " + channel + " (DM) BUT no 'to' Paramater was specfied");
return new GameClient[0];
}
}
Logger.ErrorPrint(user.Username + " Sent message in unknown channel: " + (byte)channel);
return new GameClient[0]; // No recipiants
}
public static string DoCorrections(string message)
{
if (!ConfigReader.DoCorrections)
return message;
foreach(Correction correct in CorrectedWords)
message = message.Replace(correct.FilteredWord, correct.ReplacedWord);
return message;
}
public static string EscapeMessage(string message)
{
return message.Replace("<", "&lt;");
}
public static string FormatChatForOthers(User user, ChatChannel channel, string message)
{
switch (channel)
{
case ChatChannel.All:
if (user.Moderator || user.Administrator)
return Messages.FormatGlobalChatMessageForMod(user.Username, message);
else
return Messages.FormatGlobalChatMessage(user.Username, message);
case ChatChannel.Ads:
return Messages.FormatAdsChatMessage(user.Username, message);
case ChatChannel.Buddies:
return Messages.FormatBuddyChatMessage(user.Username, message);
case ChatChannel.Dm:
if (user.Moderator || user.Administrator)
return Messages.FormatDirectMessageForMod(user.Username, message);
else
return Messages.FormatDirectMessage(user.Username, message);
case ChatChannel.Near:
return Messages.FormatNearbyChatMessage(user.Username, message);
case ChatChannel.Isle:
return Messages.FormatIsleChatMessage(user.Username, message);
case ChatChannel.Here:
return Messages.FormatHereChatMessage(user.Username, message);
case ChatChannel.Mod:
if (user.Moderator || user.Administrator)
return Messages.FormatModChatMessage(user.Username, message);
else
{
Logger.HackerPrint(user.Username + " Tried to send in mod chat without being a moderator. (Hack/Code Attempt)");
return user.Username + " is a hacker! (Sent in mod channel without being a mod) Maybe ban?";
}
case ChatChannel.Admin:
if (user.Administrator)
return Messages.FormatAdminChatMessage(user.Username, message);
else
{
Logger.HackerPrint(user.Username + " Tried to send in mod chat without being a moderator. (Hack/Code Attempt)");
return user.Username + " is a hacker! (Sent in admin channel without being a admin) Maybe ban?";
}
default:
Logger.ErrorPrint(user.Username + " is trying to end a message in unknown channel " + channel.ToString("X"));
return "not implemented yet :(";
}
}
public static string FormatChatForSender(User user, ChatChannel channel, string message, string dmRecipiant=null)
{
switch (channel)
{
case ChatChannel.All:
if (user.Moderator || user.Administrator)
return Messages.FormatGlobalChatMessageForMod(user.Username, message);
else
return Messages.FormatGlobalChatMessage(user.Username, message);
case ChatChannel.Ads:
int numbListening = GameServer.GetNumberOfPlayersListeningToAdsChat(); // vry specific function ik
return Messages.FormatAdsChatForSender(numbListening-1, user.Username, message);
case ChatChannel.Buddies:
return Messages.FormatBuddyChatMessageForSender(user.Friends.Count, user.Username, message);
case ChatChannel.Isle:
int inIsle = 0;
if (World.InIsle(user.X, user.Y))
inIsle = GameServer.GetUsersUsersInIsle(World.GetIsle(user.X, user.Y), false, false).Length -1;
return Messages.FormatIsleChatMessageForSender(inIsle, user.Username, message);
case ChatChannel.Here:
int usersHere = GameServer.GetUsersAt(user.X, user.Y, false, false).Length -1;
return Messages.FormatHereChatMessageForSender(usersHere, user.Username, message);
case ChatChannel.Near:
int nearbyUsers = GameServer.GetNearbyUsers(user.X, user.Y, false, false).Length -1;
return Messages.FormatNearChatMessageForSender(nearbyUsers, user.Username, message);
case ChatChannel.Mod:
int modsOnline = GameServer.GetNumberOfModsOnline() - 1;
return Messages.FormatModChatForSender(modsOnline, user.Username, message);
case ChatChannel.Admin:
int adminsOnline = GameServer.GetNumberOfAdminsOnline() - 1;
return Messages.FormatAdminChatForSender(adminsOnline, user.Username, message);
case ChatChannel.Dm:
return Messages.FormatDirectChatMessageForSender(user.Username, dmRecipiant, message);
default:
Logger.ErrorPrint(user.Username + " is trying to end a message in unknown channel " + channel.ToString("X"));
return "not implemented yet :(";
}
}
public static string NonViolationChecks(User user, string message)
{
// Check if contains password.
if (message.ToLower().Contains(user.Password.ToLower()))
return Messages.PasswordNotice;
// Check if ALL CAPS
string[] wordsSaid;
if (message.Contains(' '))
wordsSaid = message.Split(' ');
else
wordsSaid = new string[] { message };
foreach (string word in wordsSaid)
{
string lettersOnly = "";
foreach(char c in word)
{
if((byte)c >= (byte)'A' && (byte)c <= (byte)'z') // is letter
{
lettersOnly += c;
}
}
if (lettersOnly.ToUpper() == lettersOnly && lettersOnly.Length >= 5)
return Messages.CapsNotice;
}
return null;
}
public static Reason GetReason(string name)
{
foreach (Reason reason in Reasons)
if (reason.Name == name)
return reason;
throw new KeyNotFoundException("Reason " + name + " not found.");
}
}
}

View file

@ -0,0 +1,246 @@
using HISP.Player;
using HISP.Server;
using System;
using System.Collections.Generic;
namespace HISP.Game.Chat
{
class Command
{
public static bool Give(string message, string[] args, User user)
{
if (args.Length <= 0)
return false;
if (!user.Administrator)
return false;
if(args[0] == "OBJECT")
{
int itemId = 0;
try
{
itemId = int.Parse(args[1]);
Item.GetItemById(itemId);
ItemInstance newItemInstance = new ItemInstance(itemId);
user.Inventory.AddIgnoringFull(newItemInstance);
}
catch(Exception)
{
return false;
}
}
if (args[0] == "MONEY")
{
int money = 0;
try
{
money = int.Parse(args[1]);
user.Money += money;
}
catch (Exception)
{
return false;
}
}
if (args[0] == "QUEST")
{
int questId = 0;
try
{
questId = int.Parse(args[1]);
Quest.ActivateQuest(user, Quest.GetQuestById(questId));
}
catch (Exception)
{
return false;
}
}
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool Stickbug(string message, string[] args, User user)
{
if (args.Length <= 0)
return false;
if (!user.Administrator)
return false;
if(args[0] == "ALL")
{
foreach(GameClient client in GameServer.ConnectedClients)
{
if(client.LoggedIn)
{
byte[] swfModulePacket = PacketBuilder.CreateSwfModulePacket("fun/stickbug.swf", PacketBuilder.PACKET_SWF_MODULE_GENTLE);
client.SendPacket(swfModulePacket);
}
}
}
else
{
try
{
User victimUser = GameServer.GetUserByName(args[0]);
byte[] swfModulePacket = PacketBuilder.CreateSwfModulePacket("fun/stickbug.swf", PacketBuilder.PACKET_SWF_MODULE_GENTLE);
victimUser.LoggedinClient.SendPacket(swfModulePacket);
}
catch(KeyNotFoundException)
{
return false;
}
}
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool NoClip(string message, string[] args, User user)
{
if (!user.Administrator)
return false;
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool Kick(string message, string[] args, User user)
{
if (!user.Administrator || !user.Moderator)
return false;
if (args.Length <= 0)
return false;
try
{
User toKick = GameServer.GetUserByName(args[0]);
if (args.Length >= 2)
{
string reason = string.Join(" ", args, 1, args.Length - 1);
toKick.LoggedinClient.Kick(reason);
}
else
toKick.LoggedinClient.Kick(Messages.KickReasonKicked);
}
catch (KeyNotFoundException)
{
return false;
}
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool Goto(string message, string[] args, User user)
{
if (args.Length <= 0)
return false;
if (!user.Administrator)
return false;
if(args[0] == "PLAYER")
{
if(args.Length <= 2)
return false;
try
{
User teleportTo = GameServer.GetUserByName(args[1]);
user.Teleport(teleportTo.X, teleportTo.Y);
}
catch (KeyNotFoundException)
{
return false;
}
}
if(args[0].Contains(","))
{
try
{
string[] xy = args[0].Split(',');
int x = int.Parse(xy[0]);
int y = int.Parse(xy[1]);
user.Teleport(x, y);
}
catch(FormatException)
{
return false;
}
}
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
public static bool Mute(string message, string[] args, User user)
{
string formattedmessage = Messages.FormatPlayerCommandCompleteMessage(message.Substring(1));
if (args.Length <= 0)
{
formattedmessage += Messages.MuteHelp;
goto leave;
}
string muteType = args[0];
if (muteType == "GLOBAL")
{
user.MuteGlobal = true;
} else if (muteType == "ISLAND")
{
user.MuteIsland = true;
} else if (muteType == "NEAR")
{
user.MuteNear = true;
} else if (muteType == "HERE")
{
user.MuteHere = true;
} else if (muteType == "BUDDY")
{
user.MuteBuddy = true;
} else if (muteType == "SOCIALS")
{
user.MuteSocials = true;
}
else if (muteType == "PM")
{
user.MutePrivateMessage = true;
}
else if (muteType == "BR")
{
user.MuteBuddyRequests = true;
}
else if (muteType == "LOGINS")
{
user.MuteLogins = true;
}
else if (muteType == "ALL")
{
user.MuteAll = true;
} else
{
formattedmessage += Messages.MuteHelp;
goto leave;
}
leave:;
byte[] chatPacket = PacketBuilder.CreateChat(formattedmessage, PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
}
}
}

View file

@ -0,0 +1,347 @@
using System;
using System.Collections.Generic;
using HISP.Server;
namespace HISP.Game
{
class DroppedItems
{
public struct DroppedItem
{
public int X;
public int Y;
public int DespawnTimer;
public ItemInstance instance;
}
private static int epoch = 0;
private static List<DroppedItem> droppedItemsList = new List<DroppedItem>();
public static int GetCountOfItem(Item.ItemInformation item)
{
DroppedItem[] dropedItems = droppedItemsList.ToArray();
int count = 0;
foreach(DroppedItem droppedItem in dropedItems)
{
if (droppedItem.instance == null)
{
RemoveDroppedItem(droppedItem);
continue;
}
if(droppedItem.instance.ItemId == item.Id)
{
count++;
}
}
return count;
}
public static DroppedItem[] GetItemsAt(int x, int y)
{
DroppedItem[] dropedItems = droppedItemsList.ToArray();
List<DroppedItem> items = new List<DroppedItem>();
foreach(DroppedItem droppedItem in dropedItems)
{
if(droppedItem.X == x && droppedItem.Y == y)
{
items.Add(droppedItem);
}
}
return items.ToArray();
}
public static void ReadFromDatabase()
{
DroppedItem[] items = Database.GetDroppedItems();
foreach (DroppedItem droppedItem in items)
droppedItemsList.Add(droppedItem);
}
public static void Update()
{
int epoch_new = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
DespawnItems(epoch, epoch_new);
GenerateItems();
}
public static void RemoveDroppedItem(DroppedItem item)
{
int randomId = item.instance.RandomId;
Database.RemoveDroppedItem(randomId);
droppedItemsList.Remove(item);
}
public static bool IsDroppedItemExist(int randomId)
{
try
{
GetDroppedItemById(randomId);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public static DroppedItem GetDroppedItemById(int randomId)
{
DroppedItem[] dropedItems = droppedItemsList.ToArray();
foreach (DroppedItem item in dropedItems)
{
if(item.instance.RandomId == randomId)
{
return item;
}
}
throw new KeyNotFoundException("Random id: " + randomId.ToString() + " not found");
}
public static void DespawnItems(int old_epoch, int new_epoch)
{
int removedCount = 0;
DroppedItem[] items = droppedItemsList.ToArray();
foreach (DroppedItem item in items)
{
if(new_epoch + item.DespawnTimer < old_epoch)
{
if(GameServer.GetUsersAt(item.X, item.Y,true,true).Length == 0)
{
RemoveDroppedItem(item);
removedCount++;
}
}
}
if(removedCount > 0)
epoch = new_epoch;
}
public static void AddItem(ItemInstance item, int x, int y)
{
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = x;
droppedItem.Y = y;
droppedItem.DespawnTimer = 1500;
droppedItem.instance = item;
droppedItemsList.Add(droppedItem);
}
public static void GenerateItems()
{
int newItems = 0;
foreach (Item.ItemInformation item in Item.Items)
{
int count = GetCountOfItem(item);
while (count < item.SpawnParamaters.SpawnCap)
{
count++;
int despawnTimer = GameServer.RandomNumberGenerator.Next(900, 1500);
if (item.SpawnParamaters.SpawnInZone != null)
{
World.Zone spawnArea = World.GetZoneByName(item.SpawnParamaters.SpawnInZone);
while(true)
{
// Pick a random location inside the zone
int tryX = GameServer.RandomNumberGenerator.Next(spawnArea.StartX, spawnArea.EndX);
int tryY = GameServer.RandomNumberGenerator.Next(spawnArea.StartY, spawnArea.EndY);
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
{
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type; // Is it the right type?
if (item.SpawnParamaters.SpawnOnTileType == TileType)
{
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = tryX;
droppedItem.Y = tryY;
droppedItem.DespawnTimer = despawnTimer;
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in ZONE: " + spawnArea.Name + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
newItems++;
break;
}
else
{
continue;
}
}
else
{
continue;
}
}
}
else if (item.SpawnParamaters.SpawnOnSpecialTile != null)
{
while(true)
{
// Pick a random special tile
World.SpecialTile[] possileTiles = World.GetSpecialTilesByName(item.SpawnParamaters.SpawnOnSpecialTile);
World.SpecialTile spawnOn = possileTiles[GameServer.RandomNumberGenerator.Next(0, possileTiles.Length)];
if (Map.CheckPassable(spawnOn.X, spawnOn.Y))
{
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = spawnOn.X;
droppedItem.Y = spawnOn.Y;
droppedItem.DespawnTimer = despawnTimer;
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
newItems++;
break;
}
else
{
continue;
}
}
}
else if (item.SpawnParamaters.SpawnNearSpecialTile != null)
{
while (true)
{
// Pick a random special tile
World.SpecialTile[] possileTiles = World.GetSpecialTilesByName(item.SpawnParamaters.SpawnNearSpecialTile);
World.SpecialTile spawnNearTile = possileTiles[GameServer.RandomNumberGenerator.Next(0, possileTiles.Length)];
// Pick a direction to try spawn in
int direction = GameServer.RandomNumberGenerator.Next(0, 4);
int tryX = 0;
int tryY = 0;
if (direction == 0)
{
tryX = spawnNearTile.X + 1;
tryY = spawnNearTile.Y;
}
else if(direction == 1)
{
tryX = spawnNearTile.X - 1;
tryY = spawnNearTile.Y;
}
else if(direction == 3)
{
tryX = spawnNearTile.X;
tryY = spawnNearTile.Y + 1;
}
else if (direction == 4)
{
tryX = spawnNearTile.X;
tryY = spawnNearTile.Y - 1;
}
if (World.InSpecialTile(tryX, tryY))
{
World.SpecialTile tile = World.GetSpecialTile(tryX, tryY);
if (tile.Code != null)
continue;
}
if (Map.CheckPassable(tryX, tryY))
{
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = tryX;
droppedItem.Y = tryY;
droppedItem.DespawnTimer = despawnTimer;
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
newItems++;
break;
}
else
{
continue;
}
}
}
else if (item.SpawnParamaters.SpawnOnTileType != null)
{
while (true)
{
// Pick a random isle:
int isleId = GameServer.RandomNumberGenerator.Next(0, World.Isles.Count);
World.Isle isle = World.Isles[isleId];
// Pick a random location inside the isle
int tryX = GameServer.RandomNumberGenerator.Next(isle.StartX, isle.EndX);
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY)) // Can the player walk here?
{
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type; // Is it the right type?
if (item.SpawnParamaters.SpawnOnTileType == TileType)
{
ItemInstance instance = new ItemInstance(item.Id);
DroppedItem droppedItem = new DroppedItem();
droppedItem.X = tryX;
droppedItem.Y = tryY;
droppedItem.DespawnTimer = despawnTimer;
droppedItem.instance = instance;
droppedItemsList.Add(droppedItem);
Database.AddDroppedItem(droppedItem);
Logger.DebugPrint("Created Item ID: " + instance.ItemId + " in " + isle.Name + " at: X: " + droppedItem.X + " Y: " + droppedItem.Y);
newItems++;
break;
}
else
{
continue;
}
}
else
{
continue;
}
}
}
}
}
}
public static void Init()
{
ReadFromDatabase();
Logger.InfoPrint("Generating items, (this may take awhile on a fresh database!)");
GenerateItems();
}
}
}

View file

@ -0,0 +1,10 @@
using System;
namespace HISP.Game
{
// Inventory
class InventoryException : Exception { };
class InventoryFullException : InventoryException { };
class InventoryMaxStackException : InventoryException { };
}

View file

@ -0,0 +1,547 @@
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game.Horse
{
class HorseInfo
{
public enum StatType
{
AGILITY,
CONFORMATION,
ENDURANCE,
PERSONALITY,
SPEED,
STRENGTH,
INTELIGENCE
}
public class StatCalculator
{
public StatCalculator(HorseInstance horse, StatType type)
{
baseHorse = horse;
horseStat = type;
}
private StatType horseStat;
private HorseInstance baseHorse;
public int BaseValue
{
get
{
switch (horseStat)
{
case StatType.AGILITY:
return baseHorse.Breed.BaseStats.Agility;
case StatType.CONFORMATION:
return baseHorse.Breed.BaseStats.Conformation;
case StatType.ENDURANCE:
return baseHorse.Breed.BaseStats.Endurance;
case StatType.PERSONALITY:
return baseHorse.Breed.BaseStats.Personality;
case StatType.SPEED:
return baseHorse.Breed.BaseStats.Speed;
case StatType.STRENGTH:
return baseHorse.Breed.BaseStats.Strength;
case StatType.INTELIGENCE:
return baseHorse.Breed.BaseStats.Inteligence;
default:
return 0;
}
}
}
public int MaxValue
{
get
{
return BaseValue * 2;
}
}
public int BreedValue
{
get
{
return BaseValue + BreedOffset;
}
}
public int BreedOffset
{
get
{
switch (horseStat)
{
case StatType.AGILITY:
return baseHorse.AdvancedStats.Agility;
case StatType.CONFORMATION:
return baseHorse.AdvancedStats.Conformation;
case StatType.ENDURANCE:
return baseHorse.AdvancedStats.Endurance;
case StatType.PERSONALITY:
return baseHorse.AdvancedStats.Personality;
case StatType.SPEED:
return baseHorse.AdvancedStats.Speed;
case StatType.STRENGTH:
return baseHorse.AdvancedStats.Strength;
case StatType.INTELIGENCE:
return baseHorse.AdvancedStats.Inteligence;
default:
return 0;
}
}
set
{
switch (horseStat)
{
case StatType.AGILITY:
baseHorse.AdvancedStats.Agility = value;
break;
case StatType.CONFORMATION:
baseHorse.AdvancedStats.Conformation = value;
break;
case StatType.ENDURANCE:
baseHorse.AdvancedStats.Endurance = value;
break;
case StatType.PERSONALITY:
baseHorse.AdvancedStats.Personality = value;
break;
case StatType.SPEED:
baseHorse.AdvancedStats.Speed = value;
break;
case StatType.STRENGTH:
baseHorse.AdvancedStats.Strength = value;
break;
case StatType.INTELIGENCE:
baseHorse.AdvancedStats.Inteligence = value;
break;
}
}
}
public int CompanionOffset
{
get
{
int offsetBy = 0;
if (baseHorse.Equipment.Companion != null)
offsetBy += getOffetFrom(baseHorse.Equipment.Companion);
return offsetBy;
}
}
public int TackOffset
{
get
{
int offsetBy = 0;
if (baseHorse.Equipment.Saddle != null)
offsetBy += getOffetFrom(baseHorse.Equipment.Saddle);
if (baseHorse.Equipment.SaddlePad != null)
offsetBy += getOffetFrom(baseHorse.Equipment.SaddlePad);
if (baseHorse.Equipment.Bridle != null)
offsetBy += getOffetFrom(baseHorse.Equipment.Bridle);
return offsetBy;
}
}
public int Total
{
get
{
return BreedValue + CompanionOffset + TackOffset;
}
}
private int getOffetFrom(Item.ItemInformation tackPeice)
{
int offsetBy = 0;
foreach (Item.Effects effect in baseHorse.Equipment.Bridle.Effects)
{
string effects = effect.EffectsWhat;
switch (effects)
{
case "AGILITYOFFSET":
if (horseStat == StatType.AGILITY)
offsetBy += effect.EffectAmount;
break;
case "CONFORMATIONOFFSET":
if (horseStat == StatType.CONFORMATION)
offsetBy += effect.EffectAmount;
break;
case "ENDURANCEOFFSET":
if (horseStat == StatType.ENDURANCE)
offsetBy += effect.EffectAmount;
break;
case "PERSONALITYOFFSET":
if (horseStat == StatType.PERSONALITY)
offsetBy += effect.EffectAmount;
break;
case "SPEEDOFFSET":
if (horseStat == StatType.SPEED)
offsetBy += effect.EffectAmount;
break;
case "STRENGTHOFFSET":
if (horseStat == StatType.STRENGTH)
offsetBy += effect.EffectAmount;
break;
case "INTELLIGENCEOFFSET":
if (horseStat == StatType.INTELIGENCE)
offsetBy += effect.EffectAmount;
break;
}
}
return offsetBy;
}
}
public class AdvancedStats
{
public AdvancedStats(HorseInstance horse, int newSpeed,int newStrength, int newConformation, int newAgility, int newInteligence, int newEndurance, int newPersonality, int newHeight)
{
if(horse != null)
baseHorse = horse;
speed = newSpeed;
strength = newStrength;
conformation = newConformation;
agility = newAgility;
endurance = newEndurance;
inteligence = newInteligence;
personality = newPersonality;
Height = newHeight;
}
public int Speed
{
get
{
return speed;
}
set
{
if (value > ((baseHorse.Breed.BaseStats.Speed * 2) - baseHorse.Breed.BaseStats.Speed))
value = (baseHorse.Breed.BaseStats.Speed - baseHorse.Breed.BaseStats.Speed * 2);
Database.SetHorseSpeed(baseHorse.RandomId, value);
speed = value;
}
}
public int Strength
{
get
{
return strength;
}
set
{
if (value > ((baseHorse.Breed.BaseStats.Strength * 2)- baseHorse.Breed.BaseStats.Strength))
value = ((baseHorse.Breed.BaseStats.Strength * 2) - baseHorse.Breed.BaseStats.Strength);
Database.SetHorseStrength(baseHorse.RandomId, value);
strength = value;
}
}
public int Conformation
{
get
{
return conformation;
}
set
{
if (value > ((baseHorse.Breed.BaseStats.Conformation * 2) - baseHorse.Breed.BaseStats.Conformation))
value = ((baseHorse.Breed.BaseStats.Conformation * 2) - baseHorse.Breed.BaseStats.Conformation);
Database.SetHorseConformation(baseHorse.RandomId, value);
conformation = value;
}
}
public int Agility
{
get
{
return agility;
}
set
{
if (value > ((baseHorse.Breed.BaseStats.Agility * 2) - baseHorse.Breed.BaseStats.Agility))
value = ((baseHorse.Breed.BaseStats.Agility * 2) - baseHorse.Breed.BaseStats.Agility);
Database.SetHorseAgility(baseHorse.RandomId, value);
agility = value;
}
}
public int Endurance
{
get
{
return endurance;
}
set
{
if (value > ((baseHorse.Breed.BaseStats.Endurance * 2) - baseHorse.Breed.BaseStats.Endurance))
value = ((baseHorse.Breed.BaseStats.Endurance * 2) - baseHorse.Breed.BaseStats.Endurance);
Database.SetHorseEndurance(baseHorse.RandomId, value);
endurance = value;
}
}
public int Inteligence
{
get
{
return inteligence;
}
set
{
if (value > ((baseHorse.Breed.BaseStats.Inteligence* 2) - baseHorse.Breed.BaseStats.Inteligence))
value = ((baseHorse.Breed.BaseStats.Inteligence * 2) - baseHorse.Breed.BaseStats.Inteligence);
Database.SetHorseInteligence(baseHorse.RandomId, value);
inteligence = value;
}
}
public int Personality
{
get
{
return personality;
}
set
{
if (value > ((baseHorse.Breed.BaseStats.Personality * 2) - baseHorse.Breed.BaseStats.Personality))
value = ((baseHorse.Breed.BaseStats.Personality * 2) - baseHorse.Breed.BaseStats.Personality);
Database.SetHorsePersonality(baseHorse.RandomId, value);
personality = value;
}
}
public int Height;
public int MinHeight;
public int MaxHeight;
private HorseInstance baseHorse;
private int speed;
private int strength;
private int conformation;
private int agility;
private int endurance;
private int inteligence;
private int personality;
}
public class BasicStats
{
public BasicStats(HorseInstance horse, int newHealth, int newShoes, int newHunger, int newThirst, int newMood, int newGroom, int newTiredness, int newExperience)
{
baseHorse = horse;
health = newHealth;
shoes = newShoes;
hunger = newHunger;
thirst = newThirst;
mood = newMood;
groom = newGroom;
tiredness = newTiredness;
experience = newExperience;
}
public int Health
{
get
{
return health;
}
set
{
if (value > 1000)
value = 1000;
if (value < 0)
value = 0;
health = value;
Database.SetHorseHealth(baseHorse.RandomId, value);
}
}
public int Shoes
{
get
{
return shoes;
}
set
{
if (value > 1000)
value = 1000;
if (value < 0)
value = 0;
shoes = value;
Database.SetHorseShoes(baseHorse.RandomId, value);
}
}
public int Hunger {
get
{
return hunger;
}
set
{
if (value > 1000)
value = 1000;
if (value < 0)
value = 0;
hunger = value;
Database.SetHorseHunger(baseHorse.RandomId, value);
}
}
public int Thirst
{
get
{
return thirst;
}
set
{
if (value > 1000)
value = 1000;
if (value < 0)
value = 0;
thirst = value;
Database.SetHorseThirst(baseHorse.RandomId, value);
}
}
public int Mood
{
get
{
return mood;
}
set
{
if (value > 1000)
value = 1000;
if (value < 0)
value = 0;
mood = value;
Database.SetHorseMood(baseHorse.RandomId, value);
}
}
public int Groom
{
get
{
return groom;
}
set
{
if (value > 1000)
value = 1000;
if (value < 0)
value = 0;
groom = value;
Database.SetHorseGroom(baseHorse.RandomId, value);
}
}
public int Tiredness
{
get
{
return tiredness;
}
set
{
if (value > 1000)
value = 1000;
if (value < 0)
value = 0;
tiredness = value;
Database.SetHorseTiredness(baseHorse.RandomId, value);
}
}
public int Experience
{
get
{
return experience;
}
set
{
if (value < 0)
value = 0;
experience = value;
Database.SetHorseExperience(baseHorse.RandomId, value);
}
}
private HorseInstance baseHorse;
private int health;
private int shoes;
private int hunger;
private int thirst;
private int mood;
private int groom;
private int tiredness;
private int experience;
}
public struct Breed
{
public int Id;
public string Name;
public string Description;
public AdvancedStats BaseStats;
public string[] Colors;
public string SpawnOn;
public string SpawnInArea;
public string Swf;
public string Type;
}
public struct HorseEquips
{
public Item.ItemInformation Saddle;
public Item.ItemInformation SaddlePad;
public Item.ItemInformation Bridle;
public Item.ItemInformation Companion;
}
public struct Category
{
public string Name;
public string Meta;
}
public static string[] HorseNames;
public static List<Category> HorseCategories = new List<Category>();
public static List<Breed> Breeds = new List<Breed>();
public static string GenerateHorseName()
{
int indx = 0;
int max = HorseNames.Length;
int i = GameServer.RandomNumberGenerator.Next(indx, max);
return HorseNames[i];
}
public static double CalculateHands(int height)
{
return ((double)height / 4.0);
}
public static string BreedViewerSwf(HorseInstance horse, string terrainTileType)
{
double hands = CalculateHands(horse.AdvancedStats.Height);
string swf = "breedviewer.swf?terrain=" + terrainTileType + "&breed=" + horse.Breed.Swf + "&color=" + horse.Color + "&hands=" + hands.ToString();
if (horse.Equipment.Saddle != null)
swf += "&saddle=" + horse.Equipment.Saddle.EmbedSwf;
if (horse.Equipment.SaddlePad != null)
swf += "&saddlepad=" + horse.Equipment.SaddlePad.EmbedSwf;
if (horse.Equipment.Bridle != null)
swf += "&bridle=" + horse.Equipment.Bridle.EmbedSwf;
if (horse.Equipment.Companion != null)
swf += "&companion=" + horse.Equipment.Companion.EmbedSwf;
swf += "&junk=";
return swf;
}
public static Breed GetBreedById(int id)
{
foreach(Breed breed in Breeds)
{
if (breed.Id == id)
return breed;
}
throw new KeyNotFoundException("No horse breed with id " + id);
}
}
}

View file

@ -0,0 +1,188 @@

using HISP.Security;
using HISP.Server;
namespace HISP.Game.Horse
{
class HorseInstance
{
public HorseInstance(HorseInfo.Breed breed, int randomId = -1, string loadName=null, string loadDescription = "", int loadSpoiled=0, string loadCategory="KEEPER", int loadMagicUsed=0, int loadAutoSell=0)
{
RandomId = RandomID.NextRandomId(randomId);
Owner = 0;
if(loadName == null)
{
if (breed.Type == "camel")
{
name = "Wild Camel";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "cow";
}
else
{
Sex = "bull";
}
}
else if (breed.Type == "llama")
{
name = "Jungle Llama";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "male";
}
else
{
Sex = "female";
}
}
else if (breed.Type == "zebra")
{
name = "Wild Zebra";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "stallion";
}
else
{
Sex = "mare";
}
}
else
{
name = "Wild Horse";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "stallion";
}
else
{
Sex = "mare";
}
}
}
else
{
name = loadName;
}
description = loadDescription;
Breed = breed;
Color = breed.Colors[GameServer.RandomNumberGenerator.Next(0, breed.Colors.Length)];
BasicStats = new HorseInfo.BasicStats(this, 1000, 0, 1000, 1000, 500, 1000, 1000, 0);
int inteligence = (GameServer.RandomNumberGenerator.Next(breed.BaseStats.Inteligence, breed.BaseStats.Inteligence * 2)) - breed.BaseStats.Inteligence;
int personality = (GameServer.RandomNumberGenerator.Next(breed.BaseStats.Personality, breed.BaseStats.Personality * 2)) - breed.BaseStats.Personality;
int height = GameServer.RandomNumberGenerator.Next(breed.BaseStats.MinHeight, breed.BaseStats.MaxHeight);
AdvancedStats = new HorseInfo.AdvancedStats(this, 0, 0, 0, 0, inteligence, 0, personality, height);
Equipment = new HorseInfo.HorseEquips();
autosell = loadAutoSell;
category = loadCategory;
spoiled = loadSpoiled;
magicUsed = loadMagicUsed;
TrainTimer = 0;
RanchId = 0;
Leaser = 0;
}
public int RanchId;
public int Leaser;
public int RandomId;
public int Owner;
public string Name
{
get
{
return name;
}
set
{
name = value;
Database.SetHorseName(this.RandomId, name);
}
}
public string Description
{
get
{
return description;
}
set
{
description = value;
Database.SetHorseDescription(this.RandomId, value);
}
}
public string Sex;
public string Color;
public int TrainTimer;
public HorseInfo.Breed Breed;
public HorseInfo.BasicStats BasicStats;
public HorseInfo.AdvancedStats AdvancedStats;
public HorseInfo.HorseEquips Equipment;
public int AutoSell
{
get
{
return autosell;
}
set
{
Database.SetHorseAutoSell(RandomId, value);
autosell = value;
}
}
public int Spoiled
{
get
{
return spoiled;
}
set
{
Database.SetHorseSpoiled(RandomId, value);
spoiled = value;
}
}
public int MagicUsed
{
get
{
return magicUsed;
}
set
{
Database.SetHorseMagicUsed(RandomId, value);
magicUsed = value;
}
}
public string Category
{
get
{
return category;
}
set
{
Database.SetHorseCategory(RandomId, value);
category = value;
}
}
private string name;
private string description;
private int spoiled;
private int magicUsed;
private int autosell;
private string category;
public void ChangeNameWithoutUpdatingDatabase(string newName)
{
name = newName;
}
}
}

View file

@ -0,0 +1,295 @@
using HISP.Player;
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Horse
{
class WildHorse
{
public WildHorse(HorseInstance horse, int MapX = -1, int MapY = -1, int despawnTimeout=60, bool addToDatabase = true)
{
Instance = horse;
timeout = despawnTimeout;
if(MapX == -1 && MapY == -1)
{
while (true)
{
if (horse.Breed.SpawnInArea == null)
{
// Pick a random isle.
int isleId = GameServer.RandomNumberGenerator.Next(0, World.Isles.Count);
World.Isle isle = World.Isles[isleId];
// Pick x/y in isle.
int tryX = GameServer.RandomNumberGenerator.Next(isle.StartX, isle.EndX);
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
// Check Tile Type
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type;
if (TileType == horse.Breed.SpawnOn)
{
if (Map.CheckPassable(tryX, tryY)) // Can the player stand over here?
{
x = tryX;
y = tryY;
break;
}
}
}
else
{
World.Zone zone = World.GetZoneByName(horse.Breed.SpawnInArea);
// Pick x/y in zone.
int tryX = GameServer.RandomNumberGenerator.Next(zone.StartX, zone.EndX);
int tryY = GameServer.RandomNumberGenerator.Next(zone.StartY, zone.EndY);
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
// Check Tile Type
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type;
if (TileType == horse.Breed.SpawnOn)
{
if (Map.CheckPassable(tryX, tryY)) // Can the player stand over here?
{
x = tryX;
y = tryY;
break;
}
}
}
}
}
else
{
x = MapX;
y = MapY;
}
wildHorses.Add(this);
if(addToDatabase)
Database.AddWildHorse(this);
}
public void RandomWander()
{
int direction = GameServer.RandomNumberGenerator.Next(0, 3);
int tryX = this.X;
int tryY = this.Y;
switch(direction)
{
case 0:
tryX += 1;
break;
case 1:
tryX -= 1;
break;
case 2:
tryY += 1;
break;
case 3:
tryY -= 1;
break;
}
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
return;
if (World.InSpecialTile(tryX, tryY))
return;
if (Map.CheckPassable(tryX, tryY))
{
X = tryX;
Y = tryY;
return;
}
}
public void Escape()
{
while(true)
{
int tryX = X + GameServer.RandomNumberGenerator.Next(-15, 15);
int tryY = Y + GameServer.RandomNumberGenerator.Next(-15, 15);
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY))
{
X = tryX;
Y = tryY;
break;
}
}
}
public void Capture(User forUser)
{
forUser.HorseInventory.AddHorse(this.Instance);
Despawn(this);
}
private static List<WildHorse> wildHorses = new List<WildHorse>();
public static WildHorse[] WildHorses
{
get
{
return wildHorses.ToArray();
}
}
public static void GenerateHorses()
{
Logger.InfoPrint("Generating horses.");
while(wildHorses.Count < 40)
{
HorseInfo.Breed horseBreed = HorseInfo.Breeds[GameServer.RandomNumberGenerator.Next(0, HorseInfo.Breeds.Count)];
if (horseBreed.Swf == "")
continue;
if (horseBreed.SpawnInArea == "none") // no unipegs >_>
continue;
HorseInstance horseInst = new HorseInstance(horseBreed);
WildHorse wildHorse = new WildHorse(horseInst);
Logger.DebugPrint("Created " + horseBreed.Name + " at X:" + wildHorse.X + ", Y:" + wildHorse.Y);
}
}
public static void Init()
{
Database.LoadWildHorses();
GenerateHorses();
}
public static WildHorse[] GetHorsesAt(int x, int y)
{
List<WildHorse> horses = new List<WildHorse>();
foreach (WildHorse wildHorse in WildHorses)
{
if (wildHorse.X == x && wildHorse.Y == y)
horses.Add(wildHorse);
}
return horses.ToArray();
}
public static bool DoesHorseExist(int randomId)
{
foreach (WildHorse wildHorse in WildHorses)
{
if (wildHorse.Instance.RandomId == randomId)
return true;
}
return false;
}
public static WildHorse GetHorseById(int randomId)
{
foreach(WildHorse wildHorse in WildHorses)
{
if (wildHorse.Instance.RandomId == randomId)
return wildHorse;
}
throw new KeyNotFoundException("No horse with id: " + randomId + " was found.");
}
public static void Despawn(WildHorse horse)
{
Database.RemoveWildHorse(horse.Instance.RandomId);
wildHorses.Remove(horse);
}
public static void Update()
{
foreach(WildHorse wildHorse in WildHorses)
{
wildHorse.Timeout -= 1;
if (GameServer.GetUsersAt(wildHorse.X, wildHorse.Y, true, true).Length > 0)
continue;
if (wildHorse.Timeout <= 0)
Despawn(wildHorse);
if(wildHorse.Timeout % 5 == 0)
if (GameServer.RandomNumberGenerator.Next(0, 100) > 50)
wildHorse.RandomWander();
}
if(WildHorses.Length < 40)
{
GenerateHorses();
}
}
public HorseInstance Instance;
public int X
{
get
{
return x;
}
set
{
Database.SetWildHorseX(this.Instance.RandomId, value);
x = value;
}
}
public int Y
{
get
{
return y;
}
set
{
Database.SetWildHorseY(this.Instance.RandomId, value);
y = value;
}
}
public int Timeout
{
get
{
return timeout;
}
set
{
Database.SetWildHorseTimeout(this.Instance.RandomId, value);
timeout = value;
}
}
private int x;
private int y;
private int timeout;
}
}

View file

@ -0,0 +1,85 @@
using HISP.Game.Horse;
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game.Inventory
{
class HorseInventory
{
private User baseUser;
private List<HorseInstance> horsesList = new List<HorseInstance>();
public HorseInstance[] HorseList
{
get
{
return horsesList.ToArray();
}
}
public int MaxHorses
{
get
{
return 7; // will change when ranches are implemented.
}
}
public HorseInventory(User user)
{
baseUser = user;
Database.LoadHorseInventory(this, baseUser.Id);
}
public void AddHorse(HorseInstance horse, bool addToDb=true)
{
if (HorseList.Length + 1 > MaxHorses)
throw new InventoryFullException();
horse.Owner = baseUser.Id;
if(addToDb)
Database.AddHorse(horse);
horsesList.Add(horse);
}
public void DeleteHorse(HorseInstance horse)
{
Database.RemoveHorse(horse.RandomId);
horsesList.Remove(horse);
}
public bool HorseIdExist(int randomId)
{
try
{
GetHorseById(randomId);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public HorseInstance GetHorseById(int randomId)
{
foreach(HorseInstance inst in HorseList)
{
if (inst.RandomId == randomId)
return inst;
}
throw new KeyNotFoundException();
}
public HorseInstance[] GetHorsesInCategory(HorseInfo.Category category)
{
List<HorseInstance> instances = new List<HorseInstance>();
foreach(HorseInstance horse in HorseList)
{
if (horse.Category == category.Name)
{
instances.Add(horse);
}
}
return instances.ToArray();
}
}
}

View file

@ -0,0 +1,26 @@

namespace HISP.Game.Inventory
{
interface IInventory
{
void Add(ItemInstance item);
void Remove(ItemInstance item);
int Count
{
get;
}
InventoryItem[] GetItemList();
bool HasItem(int randomId);
bool HasItemId(int itemId);
InventoryItem GetItemByItemId(int itemId);
InventoryItem GetItemByRandomid(int randomId);
}
}

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace HISP.Game.Inventory
{
class InventoryItem
{
public InventoryItem()
{
ItemInstances = new List<ItemInstance>();
Infinite = false;
ItemId = 0;
}
public int ItemId;
public bool Infinite;
public List<ItemInstance> ItemInstances;
}
}

View file

@ -0,0 +1,175 @@
using System.Collections.Generic;
using System.Linq;
using HISP.Player;
using HISP.Server;
namespace HISP.Game.Inventory
{
class PlayerInventory : IInventory
{
public User BaseUser;
private List<InventoryItem> inventoryItems;
public PlayerInventory(User forUser)
{
inventoryItems = new List<InventoryItem>();
BaseUser = forUser;
ItemInstance[] instances = Database.GetPlayerInventory(BaseUser.Id).ToArray();
foreach(ItemInstance instance in instances)
{
addItem(instance, false);
}
}
public int Count
{
get
{
return inventoryItems.Count;
}
}
private void addItem(ItemInstance item, bool addToDatabase)
{
if (addToDatabase)
Database.AddItemToInventory(BaseUser.Id, item);
foreach (InventoryItem invetoryItem in inventoryItems)
{
if (invetoryItem.ItemId == item.ItemId)
{
invetoryItem.ItemInstances.Add(item);
return;
}
}
InventoryItem inventoryItem = new InventoryItem();
inventoryItem.ItemId = item.ItemId;
inventoryItem.ItemInstances.Add(item);
inventoryItems.Add(inventoryItem);
}
public InventoryItem[] GetItemList()
{
return inventoryItems.OrderBy(o => o.ItemInstances[0].GetItemInfo().SortBy).ToArray();
}
public void Remove(ItemInstance item)
{
Database.RemoveItemFromInventory(BaseUser.Id, item);
foreach (InventoryItem inventoryItem in inventoryItems)
{
if(item.ItemId == inventoryItem.ItemId)
{
foreach(ItemInstance instance in inventoryItem.ItemInstances)
{
if(instance.RandomId == item.RandomId)
{
inventoryItem.ItemInstances.Remove(instance);
if (inventoryItem.ItemInstances.Count <= 0)
inventoryItems.Remove(inventoryItem);
return;
}
}
}
}
Logger.ErrorPrint("Tried to remove item : " + item.RandomId + " from inventory when it was not in it");
}
public bool HasItem(int randomId)
{
InventoryItem[] items = GetItemList();
foreach(InventoryItem item in items)
{
ItemInstance[] instances = item.ItemInstances.ToArray();
foreach(ItemInstance instance in instances)
{
if (instance.RandomId == randomId)
return true;
}
}
return false;
}
public bool HasItemId(int itemId)
{
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
if (item.ItemId == itemId)
{
return true;
}
}
return false;
}
public InventoryItem GetItemByItemId(int itemId)
{
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
if (item.ItemId == itemId)
{
return item;
}
}
throw new KeyNotFoundException("id: " + itemId + " not found in inventory");
}
public InventoryItem GetItemByRandomid(int randomId)
{
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
ItemInstance[] instances = item.ItemInstances.ToArray();
foreach (ItemInstance instance in instances)
{
if (instance.RandomId == randomId)
return item;
}
}
throw new KeyNotFoundException("random id: " + randomId + " not found in inventory");
}
public void AddIgnoringFull(ItemInstance item)
{
addItem(item, true);
}
public void Add(ItemInstance item)
{
// Check if has max allready
if(HasItemId(item.ItemId))
{
InventoryItem items = GetItemByItemId(item.ItemId);
if (items.ItemInstances.Count >= ConfigReader.MAX_STACK)
{
throw new InventoryMaxStackException();
}
else if (Count >= Messages.DefaultInventoryMax)
{
throw new InventoryFullException();
}
}
addItem(item, true);
}
}
}

View file

@ -0,0 +1,172 @@
using HISP.Game.Services;
using HISP.Server;
using System.Collections.Generic;
using System.Linq;
namespace HISP.Game.Inventory
{
class ShopInventory : IInventory
{
private Shop baseShop;
private List<InventoryItem> inventoryItems;
public int Count
{
get
{
return inventoryItems.Count;
}
}
public ShopInventory(Shop shopkeeper)
{
baseShop = shopkeeper;
ItemInstance[] instances = Database.GetShopInventory(baseShop.Id).ToArray();
inventoryItems = new List<InventoryItem>();
foreach (ItemInstance instance in instances)
{
addItem(instance, false);
}
}
private void addItem(ItemInstance item, bool addToDatabase)
{
foreach (InventoryItem invetoryItem in inventoryItems)
{
if (invetoryItem.ItemId == item.ItemId)
{
if (invetoryItem.Infinite) // no need to add +1, theres allready infinite quanity.
return;
invetoryItem.ItemInstances.Add(item);
goto retrn;
}
}
InventoryItem inventoryItem = new InventoryItem();
inventoryItem.ItemId = item.ItemId;
inventoryItem.Infinite = false;
inventoryItem.ItemInstances.Add(item);
inventoryItems.Add(inventoryItem);
retrn:
{
if (addToDatabase)
Database.AddItemToShopInventory(baseShop.Id, item);
return;
};
}
public void AddInfinity(Item.ItemInformation itemInfo)
{
InventoryItem inventoryItem = new InventoryItem();
inventoryItem.ItemId = itemInfo.Id;
inventoryItem.Infinite = true;
for(int i = 0; i < 25; i++) // add 25
inventoryItem.ItemInstances.Add(new ItemInstance(inventoryItem.ItemId));
inventoryItems.Add(inventoryItem);
}
public void Add(ItemInstance item)
{
addItem(item, true);
}
public InventoryItem GetItemByItemId(int itemId)
{
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
if (item.ItemId == itemId)
{
return item;
}
}
throw new KeyNotFoundException("id: " + itemId + " not found in shop inventory");
}
public InventoryItem GetItemByRandomid(int randomId)
{
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
ItemInstance[] instances = item.ItemInstances.ToArray();
foreach (ItemInstance instance in instances)
{
if (instance.RandomId == randomId)
return item;
}
}
throw new KeyNotFoundException("random id: " + randomId + " not found in shop inventory");
}
public InventoryItem[] GetItemList()
{
return inventoryItems.OrderBy(o => o.ItemInstances[0].GetItemInfo().SortBy).OrderBy(o => o.Infinite).ToArray();
}
public bool HasItem(int randomId)
{
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
ItemInstance[] instances = item.ItemInstances.ToArray();
foreach (ItemInstance instance in instances)
{
if (instance.RandomId == randomId)
return true;
}
}
return false;
}
public bool HasItemId(int itemId)
{
InventoryItem[] items = GetItemList();
foreach (InventoryItem item in items)
{
if (item.ItemId == itemId)
{
return true;
}
}
return false;
}
public void Remove(ItemInstance item)
{
foreach (InventoryItem inventoryItem in inventoryItems)
{
if (item.ItemId == inventoryItem.ItemId)
{
foreach (ItemInstance instance in inventoryItem.ItemInstances)
{
if (instance.RandomId == item.RandomId)
{
inventoryItem.ItemInstances.Remove(instance);
if (inventoryItem.ItemInstances.Count <= 0)
inventoryItems.Remove(inventoryItem);
if (!inventoryItem.Infinite) // no need to bug the database.
Database.RemoveItemFromShopInventory(baseShop.Id, item);
else
inventoryItem.ItemInstances.Add(new ItemInstance(inventoryItem.ItemId)); // Gen new item in inventory to replace it.
return;
}
}
}
}
Logger.ErrorPrint("Tried to remove item : " + item.RandomId + " from inventory when it was not in it");
}
}
}

View file

@ -0,0 +1,154 @@
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game
{
class Item
{
public struct Effects
{
public string EffectsWhat;
public int EffectAmount;
}
public struct SpawnRules
{
public int SpawnCap;
public string SpawnInZone;
public string SpawnOnTileType;
public string SpawnOnSpecialTile;
public string SpawnNearSpecialTile;
}
public class ItemInformation
{
public int Id;
public string Name;
public string PluralName;
public string Description;
public int IconId;
public int SortBy;
public int SellPrice;
public string EmbedSwf;
public bool WishingWell;
public string Type;
public int[] MiscFlags;
public Effects[] Effects;
public SpawnRules SpawnParamaters;
}
public struct ThrowableItem
{
public int Id;
public string Message;
}
public static List<ItemInformation> Items = new List<ItemInformation>();
public static List<ThrowableItem> ThrowableItems = new List<ThrowableItem>();
public static int Present;
public static int MailMessage;
public static int DorothyShoes;
public static int PawneerOrder;
public static int Telescope;
public static int Pitchfork;
public static int WishingCoin;
public static int FishingPole;
public static int Earthworm;
public static ItemInformation[] GetAllWishableItems()
{
List<ItemInformation> itemInfo = new List<ItemInformation>();
foreach(ItemInformation item in Items)
{
if (item.WishingWell)
itemInfo.Add(item);
}
return itemInfo.ToArray();
}
public static bool ConsumeItem(User user, ItemInformation itmInfo)
{
bool toMuch = false;
foreach (Item.Effects effect in itmInfo.Effects)
{
switch (effect.EffectsWhat)
{
case "TIREDNESS":
if (user.Tiredness + effect.EffectAmount > 1000)
toMuch = true;
user.Tiredness += effect.EffectAmount;
break;
case "THIRST":
if (user.Thirst + effect.EffectAmount > 1000)
toMuch = true;
user.Thirst += effect.EffectAmount;
break;
case "HUNGER":
if (user.Hunger + effect.EffectAmount > 1000)
toMuch = true;
user.Hunger += effect.EffectAmount;
break;
default:
Logger.ErrorPrint("Unknown effect: " + effect.EffectsWhat);
break;
}
}
return toMuch;
}
public static bool IsThrowable(int id)
{
foreach(ThrowableItem itm in ThrowableItems)
{
if(itm.Id == id)
{
return true;
}
}
return false;
}
public static ThrowableItem GetThrowableItem(int id)
{
foreach (ThrowableItem itm in ThrowableItems)
{
if (itm.Id == id)
{
return itm;
}
}
throw new KeyNotFoundException("id: " + id + " is not a throwable item.");
}
public static bool ItemIdExist(int id)
{
try
{
GetItemById(id);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public static ItemInformation GetItemById(int id)
{
foreach(ItemInformation item in Items)
{
if(item.Id == id)
{
return item;
}
}
throw new KeyNotFoundException("Item id " + id + " Not found!");
}
}
}

View file

@ -0,0 +1,26 @@
using HISP.Security;
namespace HISP.Game
{
class ItemInstance
{
public int RandomId;
public int ItemId;
public Item.ItemInformation GetItemInfo()
{
return Item.GetItemById(ItemId);
}
public ItemInstance(int id,int randomId = -1)
{
RandomId = RandomID.NextRandomId(randomId);
ItemId = id;
}
}
}

View file

@ -0,0 +1,117 @@
using System;
using System.IO;
using HISP.Server;
namespace HISP.Game
{
class Map
{
public struct TerrainTile
{
public bool Passable;
public string Type;
}
public static int[] OverlayTileDepth;
public static int Width;
public static int Height;
public static byte[] MapData;
public static byte[] oMapData;
public static TerrainTile[] TerrainTiles;
public static int NewUserStartX;
public static int NewUserStartY;
public static int GetTileId(int x, int y, bool overlay)
{
if ((x > Width || x < 0) || (y > Height || y < 0)) // Outside map?
return 0x1;
int pos = ((x * Height) + y);
if (overlay)
return oMapData[pos];
else
return MapData[pos];
}
public static bool CheckPassable(int x, int y)
{
int tileId = GetTileId(x, y, false) - 1;
int otileId = GetTileId(x, y, true) - 1;
bool terrainPassable = TerrainTiles[tileId].Passable;
int tileset = 0;
if (otileId > 192)
{
if (World.InIsle(x, y))
tileset = World.GetIsle(x, y).Tileset;
otileId = otileId + 64 * tileset;
}
int tileDepth = OverlayTileDepth[otileId];
bool overlayPassable = false;
if (tileDepth == 0)
overlayPassable = false;
if (tileDepth == 1)
overlayPassable = false;
if (tileDepth == 2)
overlayPassable = true;
if (tileDepth == 3)
overlayPassable = true;
if ((!terrainPassable && overlayPassable) && otileId == 0)
return false;
bool passable = false;
if (!overlayPassable)
passable = false;
if (!terrainPassable)
passable = false;
if (!passable && overlayPassable)
passable = true;
return passable;
}
public static void OpenMap()
{
if(!File.Exists(ConfigReader.MapFile))
{
Logger.ErrorPrint("Map file not found.");
return;
}
byte[] worldMap = File.ReadAllBytes(ConfigReader.MapFile);
Width = BitConverter.ToInt32(worldMap, 0);
Height = BitConverter.ToInt32(worldMap, 4);
MapData = new byte[Width * Height];
oMapData = new byte[Width * Height];
int ii = 8;
for (int i = 0; i < MapData.Length; i++)
{
oMapData[i] = worldMap[ii];
MapData[i] = worldMap[ii+ 1];
ii += 2;
}
worldMap = null;
}
}
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,139 @@
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game
{
class Npc
{
public struct NpcReply
{
public int Id;
public string ReplyText;
public int GotoChatpoint;
public int RequiresQuestIdCompleted;
public int RequiresQuestIdNotCompleted;
}
public struct NpcChat
{
public int Id;
public string ChatText;
public int ActivateQuestId;
public NpcReply[] Replies;
}
public struct NpcEntry
{
public int Id;
public string Name;
public string AdminDescription;
public string ShortDescription;
public string LongDescription;
public bool Moves;
public int X;
public int Y;
public string StayOn;
public int RequiresQuestIdCompleted;
public int RequiresQuestIdNotCompleted;
public string UDLRScript;
public int UDLRStartX;
public int UDLRStartY;
public bool AdminOnly;
public bool LibarySearchable;
public int IconId;
public NpcChat[] Chatpoints;
}
public static List<NpcEntry> NpcList = new List<NpcEntry>();
public static NpcReply GetNpcReply(NpcEntry npc, int id)
{
foreach (NpcChat chatpoint in npc.Chatpoints)
{
foreach (NpcReply reply in chatpoint.Replies)
{
if (reply.Id == id)
return reply;
}
}
throw new KeyNotFoundException("Npc reply with " + id + " not found!");
}
public static NpcReply GetNpcReply(NpcChat chatpoint, int id)
{
foreach(NpcReply reply in chatpoint.Replies)
{
if (reply.Id == id)
return reply;
}
throw new KeyNotFoundException("Npc reply with " + id + " not found!");
}
public static NpcChat GetNpcChatpoint(NpcEntry npc, int chatpointId)
{
foreach(Npc.NpcChat chatpoint in npc.Chatpoints)
{
if(chatpoint.Id == chatpointId)
{
return chatpoint;
}
}
throw new KeyNotFoundException("Npc chatpoint id: " + chatpointId + " not found!");
}
public static int GetDefaultChatpoint(User user, NpcEntry npc)
{
if (Database.HasNpcStartpointSet(user.Id, npc.Id))
return Database.GetNpcStartPoint(user.Id, npc.Id);
else
return 0;
}
public static void SetDefaultChatpoint(User user, NpcEntry npc, int chatpointId)
{
if (Database.HasNpcStartpointSet(user.Id, npc.Id))
Database.SetNpcStartPoint(user.Id, npc.Id, chatpointId);
else
Database.AddNpcStartPoint(user.Id, npc.Id, chatpointId);
}
public static bool NpcExists(int id)
{
try
{
GetNpcById(id);
return true;
}
catch (KeyNotFoundException)
{
return false;
}
}
public static NpcEntry GetNpcById(int id)
{
foreach(NpcEntry npc in NpcList)
{
if (npc.Id == id)
return npc;
}
throw new KeyNotFoundException("Npc id: " + id + " not found!");
}
public static NpcEntry[] GetNpcByXAndY(int x, int y)
{
List<NpcEntry> npcs = new List<NpcEntry>();
foreach(NpcEntry npc in NpcList)
{
if (npc.X == x && npc.Y == y)
npcs.Add(npc);
}
return npcs.ToArray();
}
}
}

View file

@ -0,0 +1,288 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HISP.Game.Inventory;
using HISP.Player;
using HISP.Server;
namespace HISP.Game
{
class Quest
{
public const string Shovel = "SHOVEL";
public const string Binoculars = "BINOCS";
public const string Rake = "RAKE";
public const string MagnifyingGlass = "MAGNIFY";
public struct QuestItemInfo
{
public int ItemId;
public int Quantity;
}
public struct QuestAltActivation
{
public string Type;
public int ActivateX;
public int ActivateY;
}
public struct QuestEntry
{
public int Id;
public string Notes;
public string Title;
public int[] RequiresQuestIdCompleteStatsMenu; // Not sure what this is for.
public QuestAltActivation AltActivation;
public bool Tracked; // Should we track how many times the player has completed this quest.
// Fail Settings
public int MaxRepeats;
public int MoneyCost;
public QuestItemInfo[] ItemsRequired;
public string FailNpcChat;
public int AwardRequired;
public int[] RequiresQuestIdCompleted;
public int[] RequiresQuestIdNotCompleted;
// Success Settings
public int MoneyEarned;
public QuestItemInfo[] ItemsEarned;
public int QuestPointsEarned;
public int SetNpcChatpoint;
public int GotoNpcChatpoint;
public int WarpX;
public int WarpY;
public string SuccessMessage;
public string SuccessNpcChat;
public bool HideReplyOnFail;
public string Difficulty;
public string Author;
public int ChainedQuestId;
public bool Minigame;
}
public static List<QuestEntry> QuestList = new List<QuestEntry>();
public static int GetTotalQuestPoints()
{
int totalQp = 0;
QuestEntry[] quests = GetPublicQuestList();
foreach (QuestEntry quest in quests)
{
totalQp += quest.QuestPointsEarned;
}
return totalQp;
}
public static int GetTotalQuestsComplete(User user)
{
QuestEntry[] questList = GetPublicQuestList();
int totalComplete = 0;
foreach (QuestEntry quest in questList)
{
if (user.Quests.GetTrackedQuestAmount(quest.Id) > 0)
totalComplete++;
}
return totalComplete;
}
public static QuestEntry[] GetPublicQuestList()
{
QuestEntry[] quests = QuestList.OrderBy(o => o.Title).ToArray();
List<QuestEntry> sortedQuests = new List<QuestEntry>();
foreach (QuestEntry quest in quests)
{
if (quest.Title != null)
sortedQuests.Add(quest);
}
return sortedQuests.ToArray();
}
public static bool CanComplete(User user, QuestEntry quest)
{
if (quest.Tracked)
{
// Has completed other required quests?
foreach (int questId in quest.RequiresQuestIdCompleted)
if (user.Quests.GetTrackedQuestAmount(quest.Id) < 1)
return false;
// Has NOT competed other MUST NOT BE required quests
foreach (int questId in quest.RequiresQuestIdNotCompleted)
if (user.Quests.GetTrackedQuestAmount(quest.Id) > 1)
return false;
// Has allready tracked this quest?
if (user.Quests.GetTrackedQuestAmount(quest.Id) >= quest.MaxRepeats)
return false;
}
// Check if user has award unlocked
if (quest.AwardRequired != 0)
if (!user.Awards.HasAward(Award.GetAwardById(quest.AwardRequired)))
return false;
// Check if i have required items
foreach (QuestItemInfo itemInfo in quest.ItemsRequired)
{
bool hasThisItem = false;
InventoryItem[] items = user.Inventory.GetItemList();
foreach (InventoryItem item in items)
{
if (item.ItemId == itemInfo.ItemId && item.ItemInstances.Count >= itemInfo.Quantity)
{
hasThisItem = true;
break;
}
}
if (!hasThisItem)
return false;
}
// Have enough money?
if (user.Money < quest.MoneyCost)
return false;
return true;
}
public static bool CompleteQuest(User user, QuestEntry quest, bool npcActivation = false)
{
// Take Items
foreach (QuestItemInfo itemInfo in quest.ItemsRequired)
{
InventoryItem itm = user.Inventory.GetItemByItemId(itemInfo.ItemId);
for (int i = 0; i < itemInfo.Quantity; i++)
user.Inventory.Remove(itm.ItemInstances[0]);
}
user.Money -= quest.MoneyCost;
// Give money
user.Money += quest.MoneyEarned;
// Give items
foreach (QuestItemInfo itemInfo in quest.ItemsEarned)
{
for (int i = 0; i < itemInfo.Quantity; i++)
{
ItemInstance itm = new ItemInstance(itemInfo.ItemId);
user.Inventory.AddIgnoringFull(itm);
}
}
if (quest.WarpX != 0 && quest.WarpY != 0)
user.Teleport(quest.WarpX, quest.WarpY);
// Give quest points
user.QuestPoints += quest.QuestPointsEarned;
if (quest.ChainedQuestId != 0)
ActivateQuest(user, GetQuestById(quest.ChainedQuestId));
if (quest.Tracked)
user.Quests.TrackQuest(quest.Id);
if (quest.SuccessMessage != null)
{
byte[] ChatPacket = PacketBuilder.CreateChat(quest.SuccessMessage, PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(ChatPacket);
}
if (quest.SuccessNpcChat != null)
{
if (!npcActivation)
{
byte[] ChatPacket = PacketBuilder.CreateChat(quest.SuccessNpcChat, PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(ChatPacket);
}
}
// Check if award unlocked
int questPointsPercent = Convert.ToInt32(Math.Floor(((decimal)user.QuestPoints / (decimal)GetTotalQuestPoints()) * (decimal)100.0));
if (questPointsPercent >= 25)
user.Awards.AddAward(Award.GetAwardById(1)); // 25% Quest Completion Award.
if (questPointsPercent >= 50)
user.Awards.AddAward(Award.GetAwardById(2)); // 50% Quest Completion Award.
if (questPointsPercent >= 75)
user.Awards.AddAward(Award.GetAwardById(3)); // 75% Quest Completion Award.
if (questPointsPercent >= 100)
user.Awards.AddAward(Award.GetAwardById(4)); // 100% Quest Completion Award.
// Is cloud isles quest?
if (quest.Id == 1373)
{
byte[] swfLoadPacket = PacketBuilder.CreateSwfModulePacket("ballooncutscene", PacketBuilder.PACKET_SWF_CUTSCENE);
user.LoggedinClient.SendPacket(swfLoadPacket);
}
return true;
}
public static bool FailQuest(User user, QuestEntry quest, bool npcActivation = false)
{
if (quest.FailNpcChat != null)
{
if (!npcActivation)
{
byte[] ChatPacket = PacketBuilder.CreateChat(quest.FailNpcChat, PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(ChatPacket);
}
}
return false;
}
public static bool ActivateQuest(User user, QuestEntry quest, bool npcActivation = false)
{
if (CanComplete(user, quest))
{
return CompleteQuest(user, quest, npcActivation);
}
else
{
return FailQuest(user, quest, npcActivation);
}
}
public static bool DoesQuestExist(int id)
{
try
{
GetQuestById(id);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public static QuestEntry GetQuestById(int id)
{
foreach(QuestEntry quest in QuestList)
{
if(quest.Id == id)
{
return quest;
}
}
throw new KeyNotFoundException("QuestId: " + id + " Dont exist.");
}
public static bool UseTool(User user, string tool, int x, int y)
{
foreach(QuestEntry quest in QuestList)
{
if (quest.AltActivation.Type == tool && quest.AltActivation.ActivateX == x && quest.AltActivation.ActivateY == y)
{
ActivateQuest(user, quest);
return true;
}
}
return false;
}
}
}

View file

@ -0,0 +1,84 @@
using HISP.Player;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Services
{
class Inn
{
private static List<Inn> listInns = new List<Inn>();
public static Inn[] Inns
{
get
{
return listInns.ToArray();
}
}
public int Id;
public Item.ItemInformation[] RestsOffered;
public Item.ItemInformation[] MealsOffered;
public int BuyPercentage;
public int CalculateBuyCost(Item.ItemInformation item)
{
return (int)Math.Floor((float)item.SellPrice * (100.0 / (float)BuyPercentage));
}
public Item.ItemInformation GetStockedItem(int itemId)
{
// Check if inn stock..
foreach(Item.ItemInformation offering in RestsOffered)
{
if (offering.Id == itemId)
return offering;
}
foreach (Item.ItemInformation offering in MealsOffered)
{
if (offering.Id == itemId)
return offering;
}
throw new KeyNotFoundException("Item is not stocked by this inn.");
}
public Inn(int id, int[] restsOffered, int[] mealsOffered, int buyPercentage)
{
Id = id;
List<Item.ItemInformation> itemInfos = new List<Item.ItemInformation>();
foreach(int itemId in restsOffered)
{
itemInfos.Add(Item.GetItemById(itemId));
}
RestsOffered = itemInfos.ToArray();
itemInfos.Clear();
foreach (int itemId in mealsOffered)
{
itemInfos.Add(Item.GetItemById(itemId));
}
MealsOffered = itemInfos.ToArray();
itemInfos.Clear();
itemInfos = null;
BuyPercentage = buyPercentage;
listInns.Add(this);
}
public static Inn GetInnById(int id)
{
foreach (Inn inn in Inns)
if (inn.Id == id)
return inn;
throw new KeyNotFoundException("Inn " + id + " doesnt exist.");
}
}
}

View file

@ -0,0 +1,61 @@
using HISP.Game.Inventory;
using HISP.Server;
using System;
using System.Collections.Generic;
namespace HISP.Game.Services
{
class Shop
{
public int Id;
public string[] BuysItemTypes;
public int BuyPricePercentage;
public int SellPricePercentage;
public ShopInventory Inventory;
public Shop(int[] infiniteStocks)
{
Id = ShopList.Count+1;
this.Inventory = new ShopInventory(this);
foreach(int stock in infiniteStocks)
{
if (Item.ItemIdExist(stock))
this.Inventory.AddInfinity(Item.GetItemById(stock));
else
Logger.WarnPrint("Item ID: " + stock + " Does not exist.");
}
Shop.ShopList.Add(this);
}
public int CalculateBuyCost(Item.ItemInformation item)
{
return (int)Math.Round((float)item.SellPrice * (100.0 / (float)BuyPricePercentage));
}
public int CalculateSellCost(Item.ItemInformation item)
{
return (int)Math.Round((float)item.SellPrice * (100.0 / (float)SellPricePercentage));
}
public bool CanSell(Item.ItemInformation item)
{
foreach(string ItemType in BuysItemTypes)
{
if(ItemType == item.Type)
{
return true;
}
}
return false;
}
// Static Functions
public static List<Shop> ShopList = new List<Shop>();
public static Shop GetShopById(int id)
{
return ShopList[id-1];
}
}
}

View file

@ -0,0 +1,53 @@
using System.Collections.Generic;
namespace HISP.Game.Services
{
class Transport
{
public struct TransportLocation
{
public int Id;
public int Cost;
public int GotoX;
public int GotoY;
public string Type;
public string LocationTitle;
}
public struct TransportPoint
{
public int X;
public int Y;
public int[] Locations;
}
public static List<TransportPoint> TransportPoints = new List<TransportPoint>();
public static List<TransportLocation> TransportLocations = new List<TransportLocation>();
public static TransportPoint GetTransportPoint(int x, int y)
{
foreach(TransportPoint transportPoint in TransportPoints)
{
if (transportPoint.X == x && transportPoint.Y == y)
{
return transportPoint;
}
}
throw new KeyNotFoundException("Cannot find transport point at x:" + x + "y:" + y);
}
public static TransportLocation GetTransportLocation(int id)
{
foreach (TransportLocation transportLocation in TransportLocations)
{
if (transportLocation.Id == id)
{
return transportLocation;
}
}
throw new KeyNotFoundException("Cannot find transport location at Id:" + id);
}
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Services
{
class Vet
{
public static List<Vet> Vets = new List<Vet>();
public Vet(int id, double price)
{
Id = id;
PriceMultiplier = price;
Vets.Add(this);
}
public int Id;
public double PriceMultiplier;
public int CalculatePrice(int health)
{
double price = (1000.0 - (double)health) * PriceMultiplier;
return Convert.ToInt32(Math.Round(price));
}
public static Vet GetVetById(int id)
{
foreach(Vet vet in Vets)
{
if (id == vet.Id)
return vet;
}
throw new KeyNotFoundException("Vet with id: " + id + " Not found.");
}
}
}

View file

@ -0,0 +1,165 @@
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.SwfModules
{
class Brickpoet
{
public struct PoetryEntry {
public int Id;
public string Word;
public int Room;
}
public class PoetryPeice
{
public PoetryPeice(int PoetId, int RoomId, string PeiceWord)
{
if(!Database.GetPoetExist(PoetId, RoomId))
{
Id = PoetId;
x = GameServer.RandomNumberGenerator.Next(0, 365);
y = GameServer.RandomNumberGenerator.Next(0, 280);
Word = PeiceWord;
roomId = RoomId;
Database.AddPoetWord(PoetId, x, y, RoomId);
}
else
{
Id = PoetId;
roomId = RoomId;
Word = PeiceWord;
x = Database.GetPoetPositionX(Id, roomId);
y = Database.GetPoetPositionY(Id, roomId);
}
}
public int Id;
public int RoomId
{
get
{
return roomId;
}
}
public int X
{
get
{
return x;
}
set
{
Database.SetPoetPosition(Id, value, y, roomId);
x = value;
}
}
public int Y
{
get
{
return y;
}
set
{
Database.SetPoetPosition(Id, x, value, roomId);
y = value;
}
}
public string Word;
private int x;
private int y;
private int roomId;
}
public static List<PoetryEntry> PoetList = new List<PoetryEntry>();
private static List<PoetryPeice[]> poetryRooms = new List<PoetryPeice[]>();
public static PoetryPeice[][] PoetryRooms
{
get
{
return poetryRooms.ToArray();
}
}
private static PoetryEntry[] getPoetsInRoom(int roomId)
{
List<PoetryEntry> entries = new List<PoetryEntry>();
foreach(PoetryEntry poet in PoetList.ToArray())
{
if(poet.Room == roomId)
{
entries.Add(poet);
}
}
return entries.ToArray();
}
private static PoetryPeice[] getPoetryRoom(int roomId)
{
PoetryEntry[] poetryEntries = getPoetsInRoom(roomId);
List<PoetryPeice> peices = new List<PoetryPeice>();
foreach (PoetryEntry poetryEntry in poetryEntries)
{
PoetryPeice peice = new PoetryPeice(poetryEntry.Id, roomId, poetryEntry.Word);
peices.Add(peice);
}
return peices.ToArray();
}
public static PoetryPeice[] GetPoetryRoom(int roomId)
{
foreach(PoetryPeice[] peices in PoetryRooms)
{
if (peices[0].RoomId == roomId)
return peices;
}
throw new KeyNotFoundException("No poetry room of id: " + roomId + " exists.");
}
public static PoetryPeice GetPoetryPeice(PoetryPeice[] room, int id)
{
foreach(PoetryPeice peice in room)
{
if (peice.Id == id)
return peice;
}
throw new KeyNotFoundException("Peice with id: " + id + " not found in room.");
}
public static void LoadPoetryRooms()
{
List<int> rooms = new List<int>();
foreach(PoetryEntry entry in PoetList)
{
if (!rooms.Contains(entry.Room))
rooms.Add(entry.Room);
}
foreach(int room in rooms)
{
Logger.InfoPrint("Loading poetry room: " + room.ToString());
poetryRooms.Add(getPoetryRoom(room));
if (!Database.LastPlayerExist("P" + room))
Database.AddLastPlayer("P" + room, -1);
}
}
}
}

View file

@ -0,0 +1,117 @@
using HISP.Player;
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game
{
class Tracking
{
public enum TrackableItem
{
PirateTreasure,
Transport,
HorseCapture,
Crafting,
WishingWell,
Training,
ArenaLoss,
Trading,
HorseLease,
AutoSells,
PegasusTeamup,
TackShopGiveaway,
QuizWin,
RiddleWin,
IsleCardsGameWin,
HorsePawn,
WaterbaloonGameWin,
UnicornTeamup,
PotOfGold,
GameUpdates,
UnipegTeamup
}
public class TrackedItem
{
public TrackedItem(User sbaseUser, TrackableItem what, int itmcount)
{
What = what;
count = itmcount;
baseUser = sbaseUser;
}
public TrackableItem What;
public int Count
{
get
{
return count;
}
set
{
Database.SetTrackedItemCount(baseUser.Id, What, value);
count = value;
}
}
private int count;
private User baseUser;
}
private List<TrackedItem> trackingItems = new List<TrackedItem>();
private User baseUser;
public TrackedItem[] TrackingItems
{
get
{
return trackingItems.ToArray();
}
}
public Tracking(User user)
{
baseUser = user;
for(int i = 0; i < 20; i++)
{
TrackableItem item = (TrackableItem)i;
if(Database.HasTrackedItem(user.Id, item))
{
TrackedItem trackedItem = new TrackedItem(baseUser, item, Database.GetTrackedCount(user.Id, item));
trackingItems.Add(trackedItem);
}
}
}
public TrackedItem GetTrackedItem(TrackableItem what)
{
foreach(TrackedItem trackedItem in TrackingItems)
{
if (trackedItem.What == what)
return trackedItem;
}
// if it doesnt exist- create it
TrackedItem item = new TrackedItem(baseUser, what, 0);
Database.AddTrackedItem(baseUser.Id, what, 0);
trackingItems.Add(item);
return item;
}
public struct TrackedItemStatsMenu
{
public string What;
public string Value;
}
public static List<TrackedItemStatsMenu> TrackedItemsStatsMenu = new List<TrackedItemStatsMenu>();
public static string GetTrackedItemsStatsMenuName(TrackableItem item)
{
foreach(TrackedItemStatsMenu trackedItem in TrackedItemsStatsMenu)
{
if (trackedItem.What == item.ToString())
return trackedItem.Value;
}
throw new KeyNotFoundException("no such tracked item found.");
}
}
}

View file

@ -0,0 +1,269 @@
using System.Collections.Generic;
using HISP.Server;
namespace HISP.Game
{
class World
{
public struct Isle
{
public int StartX;
public int EndX;
public int StartY;
public int EndY;
public int Tileset;
public string Name;
}
public struct Town
{
public int StartX;
public int EndX;
public int StartY;
public int EndY;
public string Name;
}
public struct Area
{
public int StartX;
public int EndX;
public int StartY;
public int EndY;
public string Name;
}
public struct Zone
{
public int StartX;
public int EndX;
public int StartY;
public int EndY;
public string Name;
}
public struct Time
{
public int Minutes;
public int Days;
public int Years;
}
public struct SpecialTile
{
public int X;
public int Y;
public string Title;
public string Description;
public string Code;
public int ExitX;
public int ExitY;
public string AutoplaySwf;
public string TypeFlag;
}
public static Time ServerTime = new Time();
public static List<Isle> Isles = new List<Isle>();
public static List<Town> Towns = new List<Town>();
public static List<Area> Areas = new List<Area>();
public static List<Zone> Zones = new List<Zone>();
public static List<SpecialTile> SpecialTiles = new List<SpecialTile>();
public static void TickWorldClock()
{
ServerTime.Minutes += 1;
int hours = ServerTime.Minutes / 60;
// Periodically write time to database:
if (ServerTime.Minutes % 10 == 0) // every 10-in-game minutes)
Database.SetServerTime(ServerTime.Minutes, ServerTime.Days, ServerTime.Years);
if (hours == 24) // 1 day
{
ServerTime.Days += 1;
ServerTime.Minutes = 0;
}
if (ServerTime.Days == 366) // 1 year!
{
ServerTime.Days = 0;
ServerTime.Years += 1;
}
}
public static void ReadWorldData()
{
Logger.DebugPrint("Reading time from database...");
ServerTime.Minutes = Database.GetServerTime();
ServerTime.Days = Database.GetServerDay();
ServerTime.Years = Database.GetServerYear();
Logger.InfoPrint("It is " + ServerTime.Minutes / 60 + ":" + ServerTime.Minutes % 60 + " on Day " + ServerTime.Days + " in Year " + ServerTime.Years + "!!!");
}
public static bool InZone(int x, int y)
{
try
{
GetZone(x, y);
return true;
}
catch (KeyNotFoundException)
{
return false;
}
}
public static bool InArea(int x, int y)
{
try
{
GetArea(x, y);
return true;
}
catch (KeyNotFoundException)
{
return false;
}
}
public static bool InTown(int x, int y)
{
try
{
GetTown(x, y);
return true;
}
catch (KeyNotFoundException)
{
return false;
}
}
public static bool InSpecialTile(int x, int y)
{
try
{
GetSpecialTile(x, y);
return true;
}
catch (KeyNotFoundException)
{
return false;
}
}
public static bool InIsle(int x, int y)
{
try
{
GetIsle(x, y);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public static Zone GetZoneByName(string name)
{
foreach(Zone zone in Zones)
{
if (zone.Name == name)
return zone;
}
throw new KeyNotFoundException("Zone not found.");
}
public static SpecialTile[] GetSpecialTilesByName(string name)
{
List<SpecialTile> tiles = new List<SpecialTile>();
foreach(SpecialTile tile in SpecialTiles)
{
if(tile.Title == name)
{
tiles.Add(tile);
}
}
return tiles.ToArray();
}
public static SpecialTile GetSpecialTile(int x, int y)
{
foreach(SpecialTile specialTile in SpecialTiles)
{
if(specialTile.X == x && specialTile.Y == y)
{
return specialTile;
}
}
throw new KeyNotFoundException("x,y not in a special tile!");
}
public static Isle GetIsle(int x, int y)
{
foreach(Isle isle in Isles)
{
if (isle.StartX <= x && isle.EndX >= x && isle.StartY <= y && isle.EndY >= y)
{
return isle;
}
}
throw new KeyNotFoundException("x,y not in an isle!");
}
public static Zone GetZone(int x, int y)
{
foreach (Zone zone in Zones)
{
if (zone.StartX <= x && zone.EndX >= x && zone.StartY <= y && zone.EndY >= y)
{
return zone;
}
}
throw new KeyNotFoundException("x,y not in an zone!");
}
public static Area GetArea(int x, int y)
{
foreach (Area area in Areas)
{
if (area.StartX <= x && area.EndX >= x && area.StartY <= y && area.EndY >= y)
{
return area;
}
}
throw new KeyNotFoundException("x,y not in an area!");
}
public static Town GetTown(int x, int y)
{
foreach (Town town in Towns)
{
if (town.StartX <= x && town.EndX >= x && town.StartY <= y && town.EndY >= y)
{
return town;
}
}
throw new KeyNotFoundException("x,y not in a town!");
}
public static bool CanDropItems(int x, int y)
{
if (World.InSpecialTile(x, y))
{
World.SpecialTile tile = World.GetSpecialTile(x, y);
if (tile.Code != null)
return false;
}
return true;
}
public static string GetWeather()
{
return Database.GetWorldWeather();
}
}
}