mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-23 13:15:53 +12:00
teh big refactor
This commit is contained in:
parent
e3af85d511
commit
22b7d0fa27
36 changed files with 19658 additions and 21461 deletions
431
Horse Isle Server/Horse Isle Server/Game/Chat.cs
Normal file
431
Horse Isle Server/Horse Isle Server/Game/Chat.cs
Normal file
|
@ -0,0 +1,431 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using HISP.Player;
|
||||
using HISP.Server;
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
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;
|
||||
|
||||
if (user.Administrator || user.Moderator)
|
||||
if (message[0] == '%')
|
||||
return true;
|
||||
if (message[0] == '!')
|
||||
return true;
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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("<", "<");
|
||||
}
|
||||
|
||||
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:
|
||||
return Messages.FormatAdsChatMessage(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.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
209
Horse Isle Server/Horse Isle Server/Game/DroppedItems.cs
Normal file
209
Horse Isle Server/Horse Isle Server/Game/DroppedItems.cs
Normal file
|
@ -0,0 +1,209 @@
|
|||
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.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);
|
||||
for (int i = 0; i < droppedItemsList.Count; i++)
|
||||
{
|
||||
if(droppedItemsList[i].instance.RandomId == randomId)
|
||||
{
|
||||
droppedItemsList.RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
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.SpawnInArea != null)
|
||||
{
|
||||
|
||||
}
|
||||
else if (item.SpawnParamaters.SpawnOnSpecialTile != null)
|
||||
{
|
||||
|
||||
}
|
||||
else if (item.SpawnParamaters.SpawnNearSpecialTile != null)
|
||||
{
|
||||
|
||||
}
|
||||
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.InTown(tryX, tryY) || 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
40
Horse Isle Server/Horse Isle Server/Game/IInventory.cs
Normal file
40
Horse Isle Server/Horse Isle Server/Game/IInventory.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
class InventoryItem
|
||||
{
|
||||
public InventoryItem()
|
||||
{
|
||||
ItemInstances = new List<ItemInstance>();
|
||||
}
|
||||
|
||||
public int ItemId;
|
||||
public List<ItemInstance> ItemInstances;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
}
|
98
Horse Isle Server/Horse Isle Server/Game/Item.cs
Normal file
98
Horse Isle Server/Horse Isle Server/Game/Item.cs
Normal file
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
class Item
|
||||
{
|
||||
public struct Effects
|
||||
{
|
||||
public string EffectsWhat;
|
||||
public int EffectAmount;
|
||||
}
|
||||
|
||||
public struct SpawnRules
|
||||
{
|
||||
public int SpawnCap;
|
||||
public string SpawnInArea;
|
||||
public string SpawnOnTileType;
|
||||
public string SpawnOnSpecialTile;
|
||||
public string SpawnNearSpecialTile;
|
||||
}
|
||||
public struct 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 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 ItemInformation GetItemById(int id)
|
||||
{
|
||||
foreach(ItemInformation item in Items)
|
||||
{
|
||||
if(item.Id == id)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
throw new KeyNotFoundException("Item id " + id + " Not found!");
|
||||
}
|
||||
}
|
||||
}
|
26
Horse Isle Server/Horse Isle Server/Game/ItemInstance.cs
Normal file
26
Horse Isle Server/Horse Isle Server/Game/ItemInstance.cs
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
110
Horse Isle Server/Horse Isle Server/Game/Map.cs
Normal file
110
Horse Isle Server/Horse Isle Server/Game/Map.cs
Normal file
|
@ -0,0 +1,110 @@
|
|||
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;
|
||||
|
||||
bool tilePassable = false;
|
||||
if (terrainPassable || overlayPassable)
|
||||
tilePassable = true;
|
||||
if (!overlayPassable && (tileId != 0 && otileId != 0))
|
||||
tilePassable = false;
|
||||
|
||||
|
||||
|
||||
return tilePassable;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
331
Horse Isle Server/Horse Isle Server/Game/Messages.cs
Normal file
331
Horse Isle Server/Horse Isle Server/Game/Messages.cs
Normal file
|
@ -0,0 +1,331 @@
|
|||
using HISP.Server;
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
class Messages
|
||||
{
|
||||
public static int RequiredChatViolations;
|
||||
public static int DefaultInventoryMax;
|
||||
|
||||
// Tools
|
||||
public static string BinocularsNothing;
|
||||
public static string MagnifyNothing;
|
||||
public static string RakeNothing;
|
||||
public static string ShovelNothing;
|
||||
|
||||
// Announcements
|
||||
public static string NewUserMessage;
|
||||
public static string WelcomeFormat;
|
||||
public static string MotdFormat;
|
||||
public static string IdleWarningFormat;
|
||||
public static string LoginMessageForamt;
|
||||
public static string LogoutMessageFormat;
|
||||
|
||||
// Records
|
||||
public static string ProfileSavedMessage;
|
||||
|
||||
// Chat
|
||||
public static string GlobalChatFormat;
|
||||
public static string AdsChatFormat;
|
||||
public static string BuddyChatFormat;
|
||||
public static string NearChatFormat;
|
||||
public static string IsleChatFormat;
|
||||
public static string HereChatFormat;
|
||||
public static string DirectChatFormat;
|
||||
public static string ModChatFormat;
|
||||
public static string AdminChatFormat;
|
||||
|
||||
public static string GlobalChatFormatForModerators;
|
||||
public static string DirectChatFormatForModerators;
|
||||
|
||||
public static string IsleChatFormatForSender;
|
||||
public static string NearChatFormatForSender;
|
||||
public static string HereChatFormatForSender;
|
||||
public static string BuddyChatFormatForSender;
|
||||
public static string DirectChatFormatForSender;
|
||||
public static string AdminChatFormatForSender;
|
||||
public static string ModChatFormatForSender;
|
||||
|
||||
public static string ChatViolationMessageFormat;
|
||||
public static string PasswordNotice;
|
||||
public static string CapsNotice;
|
||||
|
||||
// Transport
|
||||
|
||||
public static string CantAffordTransport;
|
||||
public static string WelcomeToAreaFormat;
|
||||
|
||||
//Dropped Items
|
||||
|
||||
public static string NothingMessage;
|
||||
public static string ItemsOnGroundMessage;
|
||||
public static string GrabItemFormat;
|
||||
public static string GrabAllItemsButton;
|
||||
public static string GrabAllItemsMessage;
|
||||
public static string GrabbedItemMessage;
|
||||
public static string GrabbedAllObjectsMessage;
|
||||
public static string DroppedAnItemMessage;
|
||||
|
||||
// Inventory
|
||||
public static string InventoryItemFormat;
|
||||
public static string InventoryHeaderFormat;
|
||||
|
||||
public static string ItemDropButton;
|
||||
public static string ItemInformationButton;
|
||||
public static string ItemConsumeButton;
|
||||
public static string ItemThrowButton;
|
||||
public static string ItemUseButton;
|
||||
public static string ItemReadButton;
|
||||
|
||||
// Npc
|
||||
public static string NpcStartChatFormat;
|
||||
public static string NpcChatpointFormat;
|
||||
public static string NpcReplyFormat;
|
||||
public static string NpcInformationButton;
|
||||
public static string NpcTalkButton;
|
||||
|
||||
// Meta
|
||||
public static string IsleFormat;
|
||||
public static string TownFormat;
|
||||
public static string AreaFormat;
|
||||
public static string LocationFormat;
|
||||
public static string TransportFormat;
|
||||
|
||||
|
||||
|
||||
public static string NearbyPlayers;
|
||||
public static string North;
|
||||
public static string East;
|
||||
public static string South;
|
||||
public static string West;
|
||||
|
||||
public static string TileFormat;
|
||||
public static string Seperator;
|
||||
|
||||
public static string ExitThisPlace;
|
||||
public static string BackToMap;
|
||||
public static string LongFullLine;
|
||||
public static string MetaTerminator;
|
||||
|
||||
// Disconnect Messages
|
||||
public static string BanMessage;
|
||||
public static string IdleKickMessageFormat;
|
||||
|
||||
// Swf
|
||||
public static string BoatCutscene;
|
||||
public static string WagonCutscene;
|
||||
public static string BallonCutscene;
|
||||
public static string FormatNpcChatpoint(string name, string shortDescription, string chatText)
|
||||
{
|
||||
return NpcChatpointFormat.Replace("%NAME%", name).Replace("%DESCRIPTION%", shortDescription).Replace("%TEXT%", chatText);
|
||||
}
|
||||
|
||||
public static string FormatNpcTalkButton(int npcId)
|
||||
{
|
||||
return NpcTalkButton.Replace("%ID%", npcId.ToString());
|
||||
}
|
||||
public static string FormatNpcInformationButton(int npcId)
|
||||
{
|
||||
return NpcInformationButton.Replace("%ID%", npcId.ToString());
|
||||
}
|
||||
|
||||
|
||||
public static string FormatNpcReply(string replyText, int replyId)
|
||||
{
|
||||
return NpcReplyFormat.Replace("%TEXT%", replyText).Replace("%ID%", replyId.ToString());
|
||||
}
|
||||
|
||||
public static string FormatNpcStartChatMessage(int iconId, string name, string shortDescription, int npcId)
|
||||
{
|
||||
return NpcStartChatFormat.Replace("%ICONID%", iconId.ToString()).Replace("%NAME%", name).Replace("%DESCRIPTION%", shortDescription).Replace("%ID%", npcId.ToString());
|
||||
}
|
||||
|
||||
public static string FormatGlobalChatViolationMessage(Chat.Reason violationReason)
|
||||
{
|
||||
return ChatViolationMessageFormat.Replace("%AMOUNT%", RequiredChatViolations.ToString()).Replace("%REASON%", violationReason.Message);
|
||||
}
|
||||
|
||||
public static string FormatPlayerInventoryHeaderMeta(int itemCount, int maxItems)
|
||||
{
|
||||
return InventoryHeaderFormat.Replace("%ITEMCOUNT%", itemCount.ToString()).Replace("%MAXITEMS%", maxItems.ToString());
|
||||
}
|
||||
|
||||
public static string FormatPlayerInventoryItemMeta(int iconid, int count, string name)
|
||||
{
|
||||
return InventoryItemFormat.Replace("%ICONID%", iconid.ToString()).Replace("%COUNT%", count.ToString()).Replace("%TITLE%", name);
|
||||
}
|
||||
|
||||
public static string FormatItemThrowButton(int randomid)
|
||||
{
|
||||
return ItemThrowButton.Replace("%RANDOMID%", randomid.ToString());
|
||||
}
|
||||
public static string FormatItemConsumeButton(int randomid)
|
||||
{
|
||||
return ItemConsumeButton.Replace("%RANDOMID%", randomid.ToString());
|
||||
}
|
||||
public static string FormatItemInformationButton(int randomid)
|
||||
{
|
||||
return ItemInformationButton.Replace("%RANDOMID%", randomid.ToString());
|
||||
}
|
||||
|
||||
public static string FormatItemDropButton(int randomid)
|
||||
{
|
||||
return ItemDropButton.Replace("%RANDOMID%", randomid.ToString());
|
||||
}
|
||||
public static string FormatItemUseButton(int randomid)
|
||||
{
|
||||
return ItemUseButton.Replace("%RANDOMID%", randomid.ToString());
|
||||
}
|
||||
public static string FormatItemReadButton(int randomid)
|
||||
{
|
||||
return ItemReadButton.Replace("%RANDOMID%", randomid.ToString());
|
||||
}
|
||||
|
||||
// Meta
|
||||
public static string FormatTileName(string name)
|
||||
{
|
||||
return Messages.TileFormat.Replace("%TILENAME%", name);
|
||||
}
|
||||
public static string FormatGrabItemMessage(string name, int randomid, int iconid)
|
||||
{
|
||||
return GrabItemFormat.Replace("%ICONID%",iconid.ToString()).Replace("%ITEMNAME%", name).Replace("%RANDOMID%", randomid.ToString());
|
||||
}
|
||||
public static string FormatTransportMessage(string method, string place, int cost, int id, int x, int y)
|
||||
{
|
||||
string xy = "";
|
||||
xy += (char)(((x - 4) / 64) + 20);
|
||||
xy += (char)(((x - 4) % 64) + 20);
|
||||
|
||||
xy += (char)(((y - 1) / 64) + 20);
|
||||
xy += (char)(((y - 1) % 64) + 20);
|
||||
|
||||
int iconId = 253;
|
||||
if(method == "WAGON")
|
||||
iconId = 254;
|
||||
return TransportFormat.Replace("%METHOD%", method).Replace("%PLACE%", place).Replace("%COST%", cost.ToString()).Replace("%ID%", id.ToString()).Replace("%ICON%",iconId.ToString()).Replace("%XY%", xy);
|
||||
}
|
||||
// For all
|
||||
public static string FormatGlobalChatMessage(string username, string message)
|
||||
{
|
||||
return GlobalChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatBuddyChatMessage(string username, string message)
|
||||
{
|
||||
return BuddyChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatIsleChatMessage(string username, string message)
|
||||
{
|
||||
return IsleChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatNearbyChatMessage(string username, string message)
|
||||
{
|
||||
return NearChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatHereChatMessage(string username, string message)
|
||||
{
|
||||
return HereChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatDirectMessage(string username, string message)
|
||||
{
|
||||
return DirectChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
public static string FormatDirectMessageForMod(string username, string message)
|
||||
{
|
||||
return DirectChatFormatForModerators.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatGlobalChatMessageForMod(string username, string message)
|
||||
{
|
||||
return GlobalChatFormatForModerators.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatAdsChatMessage(string username, string message)
|
||||
{
|
||||
return AdsChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatModChatMessage(string username, string message)
|
||||
{
|
||||
return ModChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
public static string FormatAdminChatMessage(string username, string message)
|
||||
{
|
||||
return AdminChatFormat.Replace("%USERNAME%", username).Replace("%MESSAGE%", message);
|
||||
}
|
||||
|
||||
|
||||
// For Sender
|
||||
public static string FormatBuddyChatMessageForSender(int numbBuddies, string username, string message)
|
||||
{
|
||||
return BuddyChatFormatForSender.Replace("%USERNAME%", username).Replace("%MESSAGE%", message).Replace("%AMOUNT%", numbBuddies.ToString());
|
||||
}
|
||||
public static string FormatHereChatMessageForSender(int numbHere, string username, string message)
|
||||
{
|
||||
return HereChatFormatForSender.Replace("%USERNAME%", username).Replace("%MESSAGE%", message).Replace("%AMOUNT%", numbHere.ToString());
|
||||
}
|
||||
public static string FormatNearChatMessageForSender(int numbNear, string username, string message)
|
||||
{
|
||||
return NearChatFormatForSender.Replace("%USERNAME%", username).Replace("%MESSAGE%", message).Replace("%AMOUNT%", numbNear.ToString());
|
||||
}
|
||||
public static string FormatIsleChatMessageForSender(int numbIsle, string username, string message)
|
||||
{
|
||||
return IsleChatFormatForSender.Replace("%USERNAME%", username).Replace("%MESSAGE%", message).Replace("%AMOUNT%", numbIsle.ToString());
|
||||
}
|
||||
|
||||
public static string FormatAdminChatForSender(int numbAdmins, string username, string message)
|
||||
{
|
||||
return AdminChatFormatForSender.Replace("%USERNAME%", username).Replace("%MESSAGE%", message).Replace("%AMOUNT%", numbAdmins.ToString());
|
||||
}
|
||||
|
||||
public static string FormatModChatForSender(int numbMods, string username, string message)
|
||||
{
|
||||
return ModChatFormatForSender.Replace("%USERNAME%", username).Replace("%MESSAGE%", message).Replace("%AMOUNT%", numbMods.ToString());
|
||||
}
|
||||
public static string FormatDirectChatMessageForSender(string username,string toUsername, string message)
|
||||
{
|
||||
return DirectChatFormatForSender.Replace("%FROMUSER%", username).Replace("%TOUSER%", toUsername).Replace(" %MESSAGE%", message);
|
||||
}
|
||||
public static string FormatIdleWarningMessage()
|
||||
{
|
||||
return IdleWarningFormat.Replace("%WARN%", GameServer.IdleWarning.ToString()).Replace("%KICK%", GameServer.IdleTimeout.ToString());
|
||||
}
|
||||
|
||||
public static string FormatLoginMessage(string username)
|
||||
{
|
||||
return LoginMessageForamt.Replace("%USERNAME%", username);
|
||||
}
|
||||
|
||||
public static string FormatLogoutMessage(string username)
|
||||
{
|
||||
return LogoutMessageFormat.Replace("%USERNAME%", username);
|
||||
}
|
||||
|
||||
public static string FormatMOTD()
|
||||
{
|
||||
return MotdFormat.Replace("%MOTD%", ConfigReader.Motd);
|
||||
}
|
||||
public static string FormatWelcomeMessage(string username)
|
||||
{
|
||||
return WelcomeFormat.Replace("%USERNAME%", username);
|
||||
}
|
||||
|
||||
// Transport
|
||||
public static string FormatWelcomeToAreaMessage(string placeName)
|
||||
{
|
||||
return WelcomeToAreaFormat.Replace("%PLACE%", placeName);
|
||||
}
|
||||
|
||||
// Disconnect
|
||||
public static string FormatIdleKickMessage()
|
||||
{
|
||||
return IdleKickMessageFormat.Replace("%KICK%", GameServer.IdleTimeout.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
267
Horse Isle Server/Horse Isle Server/Game/Meta.cs
Normal file
267
Horse Isle Server/Horse Isle Server/Game/Meta.cs
Normal file
|
@ -0,0 +1,267 @@
|
|||
using HISP.Player;
|
||||
using HISP.Server;
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
class Meta
|
||||
{
|
||||
// Meta
|
||||
|
||||
private static string buildLocationString(int x, int y)
|
||||
{
|
||||
string locationString = "";
|
||||
|
||||
if (World.InArea(x, y))
|
||||
locationString += Messages.AreaFormat.Replace("%AREA%", World.GetArea(x, y).Name);
|
||||
if (World.InTown(x, y))
|
||||
locationString += Messages.TownFormat.Replace("%TOWN%", World.GetTown(x, y).Name);
|
||||
if (World.InIsle(x, y))
|
||||
locationString += Messages.IsleFormat.Replace("%ISLE%", World.GetIsle(x, y).Name);
|
||||
if (locationString != "")
|
||||
locationString = Messages.LocationFormat.Replace("%META%", locationString);
|
||||
return locationString;
|
||||
}
|
||||
|
||||
|
||||
private static string buildNearbyString(int x, int y)
|
||||
{
|
||||
string playersNearby = "";
|
||||
|
||||
User[] nearbyUsers = GameServer.GetNearbyUsers(x, y, true, true);
|
||||
if (nearbyUsers.Length > 1)
|
||||
{
|
||||
playersNearby += Messages.NearbyPlayers;
|
||||
playersNearby += Messages.Seperator;
|
||||
|
||||
string usersWest = "";
|
||||
string usersNorth = "";
|
||||
string usersEast = "";
|
||||
string usersSouth = "";
|
||||
foreach (User nearbyUser in nearbyUsers)
|
||||
{
|
||||
if (nearbyUser.X < x)
|
||||
{
|
||||
usersWest += " " + nearbyUser.Username + " ";
|
||||
}
|
||||
else if (nearbyUser.X > x)
|
||||
{
|
||||
usersEast += " " + nearbyUser.Username + " ";
|
||||
}
|
||||
else if (nearbyUser.Y > y)
|
||||
{
|
||||
usersSouth += " " + nearbyUser.Username + " ";
|
||||
}
|
||||
else if (nearbyUser.Y < y)
|
||||
{
|
||||
usersNorth += " " + nearbyUser.Username + " ";
|
||||
}
|
||||
}
|
||||
|
||||
if (usersEast != "")
|
||||
playersNearby += " " + Messages.East + usersEast + Messages.Seperator;
|
||||
if (usersWest != "")
|
||||
playersNearby += " " + Messages.West + usersWest + Messages.Seperator;
|
||||
if (usersSouth != "")
|
||||
playersNearby += " " + Messages.South + usersSouth + Messages.Seperator;
|
||||
if (usersNorth != "")
|
||||
playersNearby += " " + Messages.North + usersNorth + Messages.Seperator;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return playersNearby;
|
||||
|
||||
}
|
||||
private static string buildCommonInfo(int x, int y)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
message += buildNearbyString(x, y);
|
||||
|
||||
// Dropped Items
|
||||
DroppedItems.DroppedItem[] Items = DroppedItems.GetItemsAt(x, y);
|
||||
if (Items.Length == 0)
|
||||
message += Messages.NothingMessage;
|
||||
else
|
||||
{
|
||||
message += Messages.ItemsOnGroundMessage;
|
||||
foreach(DroppedItems.DroppedItem item in Items)
|
||||
{
|
||||
Item.ItemInformation itemInfo = item.instance.GetItemInfo();
|
||||
message += Messages.FormatGrabItemMessage(itemInfo.Name, item.instance.RandomId, itemInfo.IconId);
|
||||
}
|
||||
if(Items.Length > 1)
|
||||
message += Messages.GrabAllItemsButton;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string buildNpc(User user, int x, int y)
|
||||
{
|
||||
string message = "";
|
||||
Npc.NpcEntry[] entries = Npc.GetNpcByXAndY(x, y);
|
||||
if (entries.Length > 0)
|
||||
message += Messages.Seperator;
|
||||
foreach (Npc.NpcEntry ent in entries)
|
||||
{
|
||||
if (ent.AdminOnly && !user.Administrator)
|
||||
continue;
|
||||
|
||||
if (ent.RequiresQuestIdCompleted != 0)
|
||||
if (user.Quests.GetTrackedQuestAmount(ent.RequiresQuestIdNotCompleted) <= 0)
|
||||
continue;
|
||||
|
||||
if (ent.RequiresQuestIdNotCompleted != 0)
|
||||
if (user.Quests.GetTrackedQuestAmount(ent.RequiresQuestIdCompleted) >= 1)
|
||||
continue;
|
||||
|
||||
message += Messages.FormatNpcStartChatMessage(ent.IconId, ent.Name, ent.ShortDescription, ent.Id);
|
||||
if (ent.LongDescription != "")
|
||||
message += Messages.FormatNpcInformationButton(ent.Id);
|
||||
message += Messages.FormatNpcTalkButton(ent.Id);
|
||||
message += "^R1";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
public static string BuildTransportInfo(Transport.TransportPoint transportPoint)
|
||||
{
|
||||
string message = "";
|
||||
// Build list of locations
|
||||
for (int i = 0; i < transportPoint.Locations.Length; i++)
|
||||
{
|
||||
int transportLocationId = transportPoint.Locations[i];
|
||||
Transport.TransportLocation transportLocation = Transport.GetTransportLocation(transportLocationId);
|
||||
message += Messages.FormatTransportMessage(transportLocation.Type, transportLocation.LocationTitle, transportLocation.Cost, transportLocation.Id, transportLocation.GotoX, transportLocation.GotoY);
|
||||
if(i + 1 != transportPoint.Locations.Length)
|
||||
message += "^R1";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
public static string BuildSpecialTileInfo(User user, World.SpecialTile specialTile)
|
||||
{
|
||||
string message = "";
|
||||
|
||||
if (specialTile.Code == null)
|
||||
message += buildLocationString(specialTile.X, specialTile.Y)+Messages.Seperator;
|
||||
|
||||
|
||||
if (specialTile.Title != null && specialTile.Title != "")
|
||||
message += Messages.FormatTileName(specialTile.Title) + Messages.Seperator;
|
||||
|
||||
if (specialTile.Description != null && specialTile.Description != "")
|
||||
message += specialTile.Description;
|
||||
|
||||
message += buildNpc(user, specialTile.X, specialTile.Y);
|
||||
|
||||
if (specialTile.Code == null)
|
||||
message += buildCommonInfo(specialTile.X, specialTile.Y);
|
||||
if (specialTile.Code == "TRANSPORT")
|
||||
{
|
||||
Transport.TransportPoint point = Transport.GetTransportPoint(specialTile.X, specialTile.Y);
|
||||
message += Meta.BuildTransportInfo(point)+ "^R1";
|
||||
}
|
||||
|
||||
if (specialTile.ExitX != 0 && specialTile.ExitY != 0)
|
||||
message += Messages.ExitThisPlace + Messages.MetaTerminator;
|
||||
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string BuildInventoryInfo(PlayerInventory inv)
|
||||
{
|
||||
string message = "";
|
||||
message += Messages.FormatPlayerInventoryHeaderMeta(inv.Count, Messages.DefaultInventoryMax);
|
||||
InventoryItem[] items = inv.GetItemList();
|
||||
foreach(InventoryItem item in items)
|
||||
{
|
||||
Item.ItemInformation itemInfo = Item.GetItemById(item.ItemId);
|
||||
string title = itemInfo.Name;
|
||||
if (item.ItemInstances.Count > 1 && itemInfo.PluralName != "")
|
||||
title = itemInfo.PluralName;
|
||||
|
||||
|
||||
message += Messages.FormatPlayerInventoryItemMeta(itemInfo.IconId, item.ItemInstances.Count, title);
|
||||
|
||||
int randomId = item.ItemInstances[0].RandomId;
|
||||
|
||||
if (itemInfo.Id == Item.Present || itemInfo.Id == Item.DorothyShoes || itemInfo.Id == Item.Telescope)
|
||||
message += Messages.FormatItemUseButton(randomId);
|
||||
|
||||
if (itemInfo.Type == "TEXT")
|
||||
message += Messages.FormatItemReadButton(randomId);
|
||||
|
||||
if (itemInfo.Type == "PLAYERFOOD")
|
||||
message += Messages.FormatItemConsumeButton(randomId);
|
||||
|
||||
if (Item.IsThrowable(itemInfo.Id))
|
||||
message += Messages.FormatItemThrowButton(randomId);
|
||||
|
||||
if (itemInfo.Type != "QUEST" && itemInfo.Type != "TEXT" && World.CanDropItems(inv.BaseUser.X, inv.BaseUser.Y))
|
||||
message += Messages.FormatItemDropButton(randomId);
|
||||
message += Messages.FormatItemInformationButton(randomId);
|
||||
message += "^R1";
|
||||
}
|
||||
|
||||
message += Messages.BackToMap;
|
||||
message += Messages.MetaTerminator;
|
||||
return message;
|
||||
}
|
||||
public static string BuildChatpoint(User user, Npc.NpcEntry npc, Npc.NpcChat chatpoint)
|
||||
{
|
||||
bool hideReplys = false;
|
||||
if (chatpoint.ActivateQuestId != 0)
|
||||
{
|
||||
Quest.QuestEntry quest = Quest.GetQuestById(chatpoint.ActivateQuestId);
|
||||
if (Quest.ActivateQuest(user, quest, true))
|
||||
{
|
||||
if(quest.GotoNpcChatpoint != -1)
|
||||
chatpoint = Npc.GetNpcChatpoint(npc,quest.GotoNpcChatpoint);
|
||||
if (quest.SuccessNpcChat != null)
|
||||
chatpoint.ChatText = quest.SuccessNpcChat;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (quest.GotoNpcChatpoint != -1)
|
||||
chatpoint = Npc.GetNpcChatpoint(npc, quest.GotoNpcChatpoint);
|
||||
if (quest.FailNpcChat != null)
|
||||
chatpoint.ChatText = quest.FailNpcChat;
|
||||
|
||||
if (quest.HideReplyOnFail)
|
||||
hideReplys = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string message = "";
|
||||
message += Messages.FormatNpcChatpoint(npc.Name, npc.ShortDescription, chatpoint.ChatText);
|
||||
foreach(Npc.NpcReply reply in chatpoint.Replies)
|
||||
{
|
||||
if(reply.RequiresQuestIdCompleted != 0)
|
||||
if (user.Quests.GetTrackedQuestAmount(reply.RequiresQuestIdCompleted) <= 0)
|
||||
continue;
|
||||
if (reply.RequiresQuestIdNotCompleted != 0)
|
||||
if (user.Quests.GetTrackedQuestAmount(reply.RequiresQuestIdCompleted) >= 1)
|
||||
continue;
|
||||
if (hideReplys)
|
||||
continue;
|
||||
message += Messages.FormatNpcReply(reply.ReplyText, reply.Id);
|
||||
}
|
||||
message += Messages.BackToMap + Messages.MetaTerminator;
|
||||
return message;
|
||||
}
|
||||
|
||||
public static string BuildMetaInfo(User user, int x, int y)
|
||||
{
|
||||
string message = "";
|
||||
message += buildLocationString(x, y);
|
||||
|
||||
message += buildNpc(user, x, y);
|
||||
|
||||
message += buildCommonInfo(x, y);
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
110
Horse Isle Server/Horse Isle Server/Game/Npc.cs
Normal file
110
Horse Isle Server/Horse Isle Server/Game/Npc.cs
Normal file
|
@ -0,0 +1,110 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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 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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
194
Horse Isle Server/Horse Isle Server/Game/Quest.cs
Normal file
194
Horse Isle Server/Horse Isle Server/Game/Quest.cs
Normal file
|
@ -0,0 +1,194 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
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[] RequiresQuestIdComplete; // 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 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 bool ActivateQuest(User user, QuestEntry quest, bool npcActivation = false)
|
||||
{
|
||||
|
||||
if (quest.Tracked)
|
||||
{
|
||||
// Has completed other required quests?
|
||||
foreach (int questId in quest.RequiresQuestIdCompleted)
|
||||
if (user.Quests.GetTrackedQuestAmount(quest.Id) < 1)
|
||||
goto Fail;
|
||||
|
||||
// Has NOT competed other MUST NOT BE required quests
|
||||
foreach (int questId in quest.RequiresQuestIdNotCompleted)
|
||||
if (user.Quests.GetTrackedQuestAmount(quest.Id) > 1)
|
||||
goto Fail;
|
||||
// Has allready tracked this quest?
|
||||
if (user.Quests.GetTrackedQuestAmount(quest.Id) >= quest.MaxRepeats)
|
||||
goto Fail;
|
||||
|
||||
}
|
||||
|
||||
// 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)
|
||||
goto Fail;
|
||||
}
|
||||
|
||||
// Have enough money?
|
||||
if (user.Money < quest.MoneyCost)
|
||||
goto Fail;
|
||||
|
||||
// Have required award (unimplemented)
|
||||
|
||||
goto Success;
|
||||
|
||||
Fail: {
|
||||
if(quest.FailNpcChat != null)
|
||||
{
|
||||
if(!npcActivation)
|
||||
{
|
||||
byte[] ChatPacket = PacketBuilder.CreateChat(quest.FailNpcChat, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
user.LoggedinClient.SendPacket(ChatPacket);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Success: {
|
||||
// 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.Add(itm);
|
||||
}
|
||||
}
|
||||
if (quest.WarpX != 0 && quest.WarpY != 0)
|
||||
GameServer.Teleport(user.LoggedinClient, 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.SuccessNpcChat != null)
|
||||
{
|
||||
if (!npcActivation)
|
||||
{
|
||||
byte[] ChatPacket = PacketBuilder.CreateChat(quest.SuccessNpcChat, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
user.LoggedinClient.SendPacket(ChatPacket);
|
||||
}
|
||||
}
|
||||
|
||||
if(quest.SuccessMessage != null)
|
||||
{
|
||||
byte[] ChatPacket = PacketBuilder.CreateChat(quest.SuccessMessage, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
user.LoggedinClient.SendPacket(ChatPacket);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
57
Horse Isle Server/Horse Isle Server/Game/Transport.cs
Normal file
57
Horse Isle Server/Horse Isle Server/Game/Transport.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
213
Horse Isle Server/Horse Isle Server/Game/World.cs
Normal file
213
Horse Isle Server/Horse Isle Server/Game/World.cs
Normal file
|
@ -0,0 +1,213 @@
|
|||
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 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<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 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 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 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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue