Implement workshops and fix more quest weirdnes.

This commit is contained in:
SilicaAndPina 2021-02-06 17:04:50 +13:00
parent cb00f79d48
commit d5762c3b07
9 changed files with 352 additions and 112 deletions

View file

@ -137,8 +137,12 @@
"workshop":{
"craft_entry":"^I%ICONID%^T6Craft a %ITEMNAME% for $%PRICE%^B4LN%ITEMID%^B4C%CRAFTID%^R1",
"requires":"^H(Requires: %REQUIRES%)",
"require":"<B>%REQCOUNT% %ITEMNAMEPLURAL%</B>",
"and":" and "
"require":"<B>%REQCOUNT% %ITEMNAME%</B>",
"and":" and ",
"no_room":"You do not have room in your inventory!",
"missing_item":"You are missing a required object.",
"craft_success":"Successfully Crafted Object!",
"no_money":"You cannot afford the workshop's fee!"
},
"drawing_rooms":{
"last_draw":"^R1^LLast Player to Draw:%USERNAME% ^R1",
@ -546847,7 +546851,7 @@
}
],
"give_item": 370,
"money_cost": 370
"money_cost": 200
},
{
"id": 13,
@ -546862,7 +546866,7 @@
}
],
"give_item": 397,
"money_cost": 397
"money_cost": 200
},
{
"id": 14,
@ -546877,7 +546881,7 @@
}
],
"give_item": 398,
"money_cost": 398
"money_cost": 200
},
{
"id": 15,
@ -546892,7 +546896,7 @@
}
],
"give_item": 399,
"money_cost": 399
"money_cost": 200
},
{
"id": 16,
@ -546907,7 +546911,7 @@
}
],
"give_item": 400,
"money_cost": 400
"money_cost": 200
}
]
},
@ -546924,7 +546928,7 @@
}
],
"give_item": 384,
"money_cost": 384
"money_cost": 100
},
{
"id": 3,
@ -546943,7 +546947,7 @@
}
],
"give_item": 385,
"money_cost": 385
"money_cost": 200
},
{
"id": 4,
@ -546962,7 +546966,7 @@
}
],
"give_item": 386,
"money_cost": 386
"money_cost": 200
},
{
"id": 5,
@ -546981,7 +546985,7 @@
}
],
"give_item": 387,
"money_cost": 387
"money_cost": 200
},
{
"id": 6,
@ -547000,7 +547004,7 @@
}
],
"give_item": 388,
"money_cost": 388
"money_cost": 200
},
{
"id": 7,
@ -547019,7 +547023,7 @@
}
],
"give_item": 389,
"money_cost": 389
"money_cost": 300
},
{
"id": 8,
@ -547038,7 +547042,7 @@
}
],
"give_item": 390,
"money_cost": 390
"money_cost": 500
},
{
"id": 9,
@ -547049,7 +547053,7 @@
}
],
"give_item": 393,
"money_cost": 393
"money_cost": 100
},
{
"id": 10,
@ -547068,7 +547072,7 @@
}
],
"give_item": 394,
"money_cost": 394
"money_cost": 200
},
{
"id": 11,
@ -547087,7 +547091,7 @@
}
],
"give_item": 395,
"money_cost": 395
"money_cost": 200
},
{
"id": 89,
@ -547106,7 +547110,7 @@
}
],
"give_item": 1364,
"money_cost": 1364
"money_cost": 1000
},
{
"id": 90,
@ -547125,7 +547129,7 @@
}
],
"give_item": 1365,
"money_cost": 1365
"money_cost": 1000
},
{
"id": 91,
@ -547144,7 +547148,7 @@
}
],
"give_item": 1366,
"money_cost": 1366
"money_cost": 1000
},
{
"id": 92,
@ -547163,7 +547167,7 @@
}
],
"give_item": 1367,
"money_cost": 1367
"money_cost": 1000
},
{
"id": 93,
@ -547182,7 +547186,7 @@
}
],
"give_item": 1368,
"money_cost": 1368
"money_cost": 1000
},
{
"id": 94,
@ -547201,7 +547205,7 @@
}
],
"give_item": 1369,
"money_cost": 1369
"money_cost": 1000
},
{
"id": 95,
@ -547220,7 +547224,7 @@
}
],
"give_item": 1370,
"money_cost": 1370
"money_cost": 1000
}
]
},
@ -547237,7 +547241,7 @@
}
],
"give_item": 440,
"money_cost": 440
"money_cost": 100
},
{
"id": 17,
@ -547248,7 +547252,7 @@
}
],
"give_item": 441,
"money_cost": 441
"money_cost": 150
},
{
"id": 18,
@ -547259,7 +547263,7 @@
}
],
"give_item": 442,
"money_cost": 442
"money_cost": 200
},
{
"id": 19,
@ -547270,7 +547274,7 @@
}
],
"give_item": 443,
"money_cost": 443
"money_cost": 200
},
{
"id": 56,
@ -547281,7 +547285,7 @@
}
],
"give_item": 567,
"money_cost": 567
"money_cost": 200
}
]
},
@ -547298,7 +547302,7 @@
}
],
"give_item": 446,
"money_cost": 446
"money_cost": 100
},
{
"id": 21,
@ -547317,7 +547321,7 @@
}
],
"give_item": 448,
"money_cost": 448
"money_cost": 300
},
{
"id": 22,
@ -547336,7 +547340,7 @@
}
],
"give_item": 449,
"money_cost": 449
"money_cost": 300
},
{
"id": 23,
@ -547355,7 +547359,7 @@
}
],
"give_item": 450,
"money_cost": 450
"money_cost": 300
},
{
"id": 24,
@ -547374,7 +547378,7 @@
}
],
"give_item": 451,
"money_cost": 451
"money_cost": 300
},
{
"id": 25,
@ -547393,7 +547397,7 @@
}
],
"give_item": 453,
"money_cost": 453
"money_cost": 300
},
{
"id": 26,
@ -547412,7 +547416,7 @@
}
],
"give_item": 454,
"money_cost": 454
"money_cost": 300
},
{
"id": 27,
@ -547431,7 +547435,7 @@
}
],
"give_item": 456,
"money_cost": 456
"money_cost": 300
},
{
"id": 28,
@ -547450,7 +547454,7 @@
}
],
"give_item": 457,
"money_cost": 457
"money_cost": 300
},
{
"id": 29,
@ -547469,7 +547473,7 @@
}
],
"give_item": 458,
"money_cost": 458
"money_cost": 300
},
{
"id": 30,
@ -547488,7 +547492,7 @@
}
],
"give_item": 459,
"money_cost": 459
"money_cost": 300
},
{
"id": 31,
@ -547507,7 +547511,7 @@
}
],
"give_item": 460,
"money_cost": 460
"money_cost": 300
},
{
"id": 32,
@ -547526,7 +547530,7 @@
}
],
"give_item": 461,
"money_cost": 461
"money_cost": 300
}
]
},
@ -547551,7 +547555,7 @@
}
],
"give_item": 462,
"money_cost": 462
"money_cost": 200
},
{
"id": 34,
@ -547570,7 +547574,7 @@
}
],
"give_item": 469,
"money_cost": 469
"money_cost": 200
},
{
"id": 35,
@ -547589,7 +547593,7 @@
}
],
"give_item": 470,
"money_cost": 470
"money_cost": 200
},
{
"id": 36,
@ -547608,7 +547612,7 @@
}
],
"give_item": 471,
"money_cost": 471
"money_cost": 200
},
{
"id": 37,
@ -547627,7 +547631,7 @@
}
],
"give_item": 472,
"money_cost": 472
"money_cost": 200
},
{
"id": 38,
@ -547642,7 +547646,7 @@
}
],
"give_item": 473,
"money_cost": 473
"money_cost": 100
},
{
"id": 39,
@ -547661,7 +547665,7 @@
}
],
"give_item": 467,
"money_cost": 467
"money_cost": 200
},
{
"id": 40,
@ -547680,7 +547684,7 @@
}
],
"give_item": 468,
"money_cost": 468
"money_cost": 200
},
{
"id": 61,
@ -547699,7 +547703,7 @@
}
],
"give_item": 788,
"money_cost": 788
"money_cost": 200
},
{
"id": 64,
@ -547718,7 +547722,7 @@
}
],
"give_item": 791,
"money_cost": 791
"money_cost": 200
},
{
"id": 65,
@ -547737,7 +547741,7 @@
}
],
"give_item": 856,
"money_cost": 856
"money_cost": 200
},
{
"id": 66,
@ -547756,7 +547760,7 @@
}
],
"give_item": 857,
"money_cost": 857
"money_cost": 200
},
{
"id": 67,
@ -547775,7 +547779,7 @@
}
],
"give_item": 858,
"money_cost": 858
"money_cost": 200
},
{
"id": 68,
@ -547794,7 +547798,7 @@
}
],
"give_item": 859,
"money_cost": 859
"money_cost": 200
},
{
"id": 77,
@ -547813,7 +547817,7 @@
}
],
"give_item": 1089,
"money_cost": 1089
"money_cost": 200
},
{
"id": 78,
@ -547832,7 +547836,7 @@
}
],
"give_item": 1090,
"money_cost": 1090
"money_cost": 200
},
{
"id": 79,
@ -547851,7 +547855,7 @@
}
],
"give_item": 1093,
"money_cost": 1093
"money_cost": 200
}
]
},
@ -547876,7 +547880,7 @@
}
],
"give_item": 571,
"money_cost": 571
"money_cost": 200
},
{
"id": 53,
@ -547895,7 +547899,7 @@
}
],
"give_item": 572,
"money_cost": 572
"money_cost": 200
},
{
"id": 54,
@ -547914,7 +547918,7 @@
}
],
"give_item": 573,
"money_cost": 573
"money_cost": 200
},
{
"id": 55,
@ -547933,7 +547937,7 @@
}
],
"give_item": 574,
"money_cost": 574
"money_cost": 200
},
{
"id": 57,
@ -547948,7 +547952,7 @@
}
],
"give_item": 578,
"money_cost": 578
"money_cost": 100
},
{
"id": 58,
@ -547967,7 +547971,7 @@
}
],
"give_item": 577,
"money_cost": 577
"money_cost": 200
},
{
"id": 59,
@ -547986,7 +547990,7 @@
}
],
"give_item": 570,
"money_cost": 570
"money_cost": 200
},
{
"id": 60,
@ -548005,7 +548009,7 @@
}
],
"give_item": 569,
"money_cost": 569
"money_cost": 200
},
{
"id": 62,
@ -548024,7 +548028,7 @@
}
],
"give_item": 789,
"money_cost": 789
"money_cost": 200
},
{
"id": 63,
@ -548043,7 +548047,7 @@
}
],
"give_item": 790,
"money_cost": 790
"money_cost": 200
},
{
"id": 69,
@ -548062,7 +548066,7 @@
}
],
"give_item": 860,
"money_cost": 860
"money_cost": 200
},
{
"id": 70,
@ -548081,7 +548085,7 @@
}
],
"give_item": 861,
"money_cost": 861
"money_cost": 200
},
{
"id": 71,
@ -548100,7 +548104,7 @@
}
],
"give_item": 862,
"money_cost": 862
"money_cost": 200
},
{
"id": 72,
@ -548119,7 +548123,7 @@
}
],
"give_item": 863,
"money_cost": 863
"money_cost": 200
},
{
"id": 80,
@ -548138,7 +548142,7 @@
}
],
"give_item": 1094,
"money_cost": 1094
"money_cost": 200
},
{
"id": 81,
@ -548157,7 +548161,7 @@
}
],
"give_item": 1092,
"money_cost": 1092
"money_cost": 200
},
{
"id": 82,
@ -548176,7 +548180,7 @@
}
],
"give_item": 1091,
"money_cost": 1091
"money_cost": 200
}
]
},
@ -548193,7 +548197,7 @@
}
],
"give_item": 1234,
"money_cost": 1234
"money_cost": 100
},
{
"id": 84,
@ -548204,7 +548208,7 @@
}
],
"give_item": 393,
"money_cost": 393
"money_cost": 100
},
{
"id": 85,
@ -548215,7 +548219,7 @@
}
],
"give_item": 1235,
"money_cost": 1235
"money_cost": 100
},
{
"id": 86,
@ -548234,7 +548238,7 @@
}
],
"give_item": 1240,
"money_cost": 1240
"money_cost": 200
},
{
"id": 87,
@ -548253,7 +548257,7 @@
}
],
"give_item": 1241,
"money_cost": 1241
"money_cost": 200
},
{
"id": 88,
@ -548272,7 +548276,7 @@
}
],
"give_item": 1242,
"money_cost": 1242
"money_cost": 200
}
]
}

View file

@ -31,7 +31,7 @@ namespace HISP.Game.Chat
return false;
}
}
if (args[0] == "MONEY")
else if (args[0] == "MONEY")
{
int money = 0;
try
@ -44,7 +44,7 @@ namespace HISP.Game.Chat
return false;
}
}
if (args[0] == "QUEST")
else if (args[0] == "QUEST")
{
int questId = 0;
try
@ -57,7 +57,10 @@ namespace HISP.Game.Chat
return false;
}
}
else
{
return false;
}
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket);
return true;
@ -220,6 +223,31 @@ namespace HISP.Game.Chat
return false;
}
}
else if(args[0] == "AREA")
{
if (args.Length < 2)
return false;
try
{
string area = string.Join(" ", args, 1, args.Length - 1);
bool teleported = false;
foreach(World.Waypoint waypnt in World.Waypoints)
{
if(waypnt.Name.ToLower().StartsWith(area.ToLower()))
{
user.Teleport(waypnt.PosX, waypnt.PosY);
teleported = true;
}
}
if(!teleported)
return false;
}
catch(Exception)
{
return false;
}
}
if(args[0].Contains(","))
{
try

View file

@ -217,6 +217,17 @@ namespace HISP.Game
public static string TackViewSetFormat;
public static string TackSetPeiceFormat;
// Workshop
public static string WorkshopCraftEntryFormat;
public static string WorkshopRequiresFormat;
public static string WorkshopRequireEntryFormat;
public static string WorkshopAnd;
public static string WorkshopNoRoomInInventory;
public static string WorkshopMissingRequiredItem;
public static string WorkshopCraftingSuccess;
public static string WorkshopCannotAfford;
// Horse
public static string BreedViewerMaximumStats;
public static string AdvancedStatFormat;
@ -569,6 +580,19 @@ namespace HISP.Game
// Click
public static string NothingInterestingHere;
public static string FormatWorkshopCraftEntry(int iconId, string itemName, int price, int itemId, int craftId)
{
return WorkshopCraftEntryFormat.Replace("%ICONID%", iconId.ToString()).Replace("%ITEMNAME%", itemName).Replace("%PRICE%", price.ToString("N0")).Replace("%ITEMID%", itemId.ToString()).Replace("%CRAFTID%", craftId.ToString());
}
public static string FormatWorkshopRequirements(string requiresTxt)
{
return WorkshopRequiresFormat.Replace("%REQUIRES%", requiresTxt);
}
public static string FormatWorkshopRequireEntry(int requiredCount, string itemNamePlural)
{
return WorkshopRequireEntryFormat.Replace("%REQCOUNT%", requiredCount.ToString("N0")).Replace("%ITEMNAME%", itemNamePlural);
}
public static string FormatDrawingRoomSaved(int slot)
{
return DrawingContentsSavedInSlotFormat.Replace("%SLOT%", slot.ToString("N0"));

View file

@ -1018,6 +1018,33 @@ namespace HISP.Game
return message;
}
private static string buildWorkshop(User user)
{
Workshop shop = Workshop.GetWorkshopAt(user.X, user.Y);
string message = "";
foreach(Workshop.CraftableItem craft in shop.CraftableItems)
{
Item.ItemInformation itmInfo = Item.GetItemById(craft.GiveItemId);
message += Messages.FormatWorkshopCraftEntry(itmInfo.IconId, itmInfo.Name, craft.MoneyCost, itmInfo.Id, craft.Id);
// Get requirements
List<string> Requirements = new List<string>();
foreach(Workshop.RequiredItem reqItem in craft.RequiredItems)
{
Item.ItemInformation requiredItemInfo = Item.GetItemById(reqItem.RequiredItemId);
string requirementTxt;
if (reqItem.RequiredItemCount <= 1)
requirementTxt = Messages.FormatWorkshopRequireEntry(reqItem.RequiredItemCount, requiredItemInfo.Name);
else
requirementTxt = Messages.FormatWorkshopRequireEntry(reqItem.RequiredItemCount, requiredItemInfo.PluralName);
Requirements.Add(requirementTxt);
}
message += Messages.FormatWorkshopRequirements(string.Join(Messages.WorkshopAnd, Requirements.ToArray()));
}
message += Messages.ExitThisPlace;
message += Messages.MetaTerminator;
return message;
}
private static string buildVet(Vet vet, User user)
{
string message = "";
@ -1127,6 +1154,10 @@ namespace HISP.Game
{
message += buildPond(user);
}
if(TileCode == "WORKSHOP")
{
message += buildWorkshop(user);
}
if(TileCode == "MUDHOLE")
{
message += buildMudHole(user);
@ -1535,24 +1566,26 @@ namespace HISP.Game
if (chatpoint.ActivateQuestId != 0)
{
Quest.QuestEntry quest = Quest.GetQuestById(chatpoint.ActivateQuestId);
if (Quest.ActivateQuest(user, quest, true))
Quest.QuestResult result = Quest.ActivateQuest(user, quest, true);
if (result.QuestCompleted)
{
user.MetaPriority = true;
if (quest.SetNpcChatpoint != -1)
Npc.SetDefaultChatpoint(user, npc, quest.SetNpcChatpoint);
if (quest.GotoNpcChatpoint != -1)
chatpoint = Npc.GetNpcChatpoint(npc,quest.GotoNpcChatpoint);
if (quest.SuccessNpcChat != null)
chatpoint.ChatText = quest.SuccessNpcChat;
if (result.SetChatpoint != -1)
Npc.SetDefaultChatpoint(user, npc, result.SetChatpoint);
if (result.GotoChatpoint != -1)
chatpoint = Npc.GetNpcChatpoint(npc, result.GotoChatpoint);
if (result.NpcChat != null)
chatpoint.ChatText = result.NpcChat;
}
else
{
if (quest.GotoNpcChatpoint != -1)
chatpoint = Npc.GetNpcChatpoint(npc, quest.GotoNpcChatpoint);
if (quest.FailNpcChat != null)
chatpoint.ChatText = quest.FailNpcChat;
if (result.GotoChatpoint != -1)
chatpoint = Npc.GetNpcChatpoint(npc, result.GotoChatpoint);
if (result.NpcChat != null)
chatpoint.ChatText = result.NpcChat;
if (quest.HideReplyOnFail)
if (result.HideRepliesOnFail)
hideReplys = true;
}
}

View file

@ -102,6 +102,23 @@ namespace HISP.Game
return sortedQuests.ToArray();
}
public class QuestResult
{
public QuestResult()
{
NpcChat = null;
SetChatpoint = -1;
GotoChatpoint = -1;
HideRepliesOnFail = false;
QuestCompleted = false;
}
public string NpcChat;
public int SetChatpoint;
public int GotoChatpoint;
public bool HideRepliesOnFail;
public bool QuestCompleted;
}
public static bool CanComplete(User user, QuestEntry quest)
{
if (quest.Tracked)
@ -153,8 +170,10 @@ namespace HISP.Game
return true;
}
public static bool CompleteQuest(User user, QuestEntry quest, bool npcActivation = false)
public static QuestResult CompleteQuest(User user, QuestEntry quest, bool npcActivation = false, QuestResult res=null)
{
if(res == null)
res = new QuestResult();
// Take Items
foreach (QuestItemInfo itemInfo in quest.ItemsRequired)
{
@ -181,12 +200,24 @@ namespace HISP.Game
// Give quest points
user.QuestPoints += quest.QuestPointsEarned;
res.QuestCompleted = true;
if (npcActivation)
{
if (quest.SuccessNpcChat != null)
res.NpcChat = quest.SuccessNpcChat;
if(quest.SetNpcChatpoint != -1)
res.SetChatpoint = quest.SetNpcChatpoint;
if(quest.GotoNpcChatpoint != -1)
res.GotoChatpoint = quest.GotoNpcChatpoint;
}
if (quest.Tracked)
user.Quests.TrackQuest(quest.Id);
if (quest.ChainedQuestId != 0)
ActivateQuest(user, Quest.GetQuestById(quest.ChainedQuestId), npcActivation);
res = ActivateQuest(user, Quest.GetQuestById(quest.ChainedQuestId), npcActivation, res);
if (quest.SuccessMessage != null)
{
@ -203,9 +234,6 @@ namespace HISP.Game
}
}
// Check if award unlocked
int questPointsPercent = Convert.ToInt32(Math.Floor(((decimal)user.QuestPoints / (decimal)GetTotalQuestPoints()) * (decimal)100.0));
if (questPointsPercent >= 25)
@ -224,10 +252,23 @@ namespace HISP.Game
user.LoggedinClient.SendPacket(swfLoadPacket);
}
return true;
return res;
}
public static bool FailQuest(User user, QuestEntry quest, bool npcActivation = false)
public static QuestResult FailQuest(User user, QuestEntry quest, bool npcActivation = false, QuestResult res=null)
{
if(res == null)
res = new QuestResult();
res.QuestCompleted = false;
if(npcActivation)
{
if(quest.GotoNpcChatpoint != -1)
res.GotoChatpoint = quest.GotoNpcChatpoint;
if(quest.HideReplyOnFail != false)
res.HideRepliesOnFail = quest.HideReplyOnFail;
if(res.SetChatpoint != -1)
res.SetChatpoint = quest.SetNpcChatpoint;
}
if (quest.FailNpcChat != null)
{
if (!npcActivation)
@ -235,19 +276,24 @@ namespace HISP.Game
byte[] ChatPacket = PacketBuilder.CreateChat(quest.FailNpcChat, PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(ChatPacket);
}
else
{
if(quest.FailNpcChat != null)
res.NpcChat = quest.FailNpcChat;
}
}
return false;
return res;
}
public static bool ActivateQuest(User user, QuestEntry quest, bool npcActivation = false)
public static QuestResult ActivateQuest(User user, QuestEntry quest, bool npcActivation = false, QuestResult res=null)
{
if (CanComplete(user, quest))
{
return CompleteQuest(user, quest, npcActivation);
return CompleteQuest(user, quest, npcActivation, res);
}
else
{
return FailQuest(user, quest, npcActivation);
return FailQuest(user, quest, npcActivation, res);
}
}

View file

@ -34,6 +34,30 @@ namespace HISP.Game.Services
public static List<Workshop> Workshops = new List<Workshop>();
public static Workshop GetWorkshopAt(int x, int y)
{
foreach(Workshop wkShop in Workshops)
{
if(wkShop.X == x && wkShop.Y == y)
{
return wkShop;
}
}
throw new KeyNotFoundException("No workshop found.");
}
public static bool CraftIdExists(int id)
{
try
{
GetCraftId(id);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public static CraftableItem GetCraftId(int id)
{
foreach(Workshop wkShop in Workshops)

View file

@ -560,11 +560,11 @@ namespace HISP.Server
craftableItem.GiveItemId = gameData.workshop[i].craftable_items[ii].give_item;
craftableItem.MoneyCost = gameData.workshop[i].craftable_items[ii].money_cost;
int totalItemsRequired = gameData.workshop[i].craftable_items[ii].required_items.Count;
for(int iii = 0; iii < 0; iii++)
for(int iii = 0; iii < totalItemsRequired; iii++)
{
Workshop.RequiredItem requiredItem = new Workshop.RequiredItem();
requiredItem.RequiredItemId = totalItemsRequired = gameData.workshop[i].craftable_items[ii].required_items[iii].req_item;
requiredItem.RequiredItemId = totalItemsRequired = gameData.workshop[i].craftable_items[ii].required_items[iii].req_quantity;
requiredItem.RequiredItemId = gameData.workshop[i].craftable_items[ii].required_items[iii].req_item;
requiredItem.RequiredItemCount = gameData.workshop[i].craftable_items[ii].required_items[iii].req_quantity;
craftableItem.RequiredItems.Add(requiredItem);
}
wkShop.CraftableItems.Add(craftableItem);
@ -761,6 +761,17 @@ namespace HISP.Server
Messages.BankDepositedMoneyFormat = gameData.messages.bank.deposit_format;
Messages.BankWithdrewMoneyFormat = gameData.messages.bank.withdraw_format;
// Workshop
Messages.WorkshopCraftEntryFormat = gameData.messages.meta.workshop.craft_entry;
Messages.WorkshopRequiresFormat = gameData.messages.meta.workshop.requires;
Messages.WorkshopRequireEntryFormat = gameData.messages.meta.workshop.require;
Messages.WorkshopAnd = gameData.messages.meta.workshop.and;
Messages.WorkshopNoRoomInInventory = gameData.messages.meta.workshop.no_room;
Messages.WorkshopMissingRequiredItem = gameData.messages.meta.workshop.missing_item;
Messages.WorkshopCraftingSuccess = gameData.messages.meta.workshop.craft_success;
Messages.WorkshopCannotAfford = gameData.messages.meta.workshop.no_money;
// Horses
Messages.AdvancedStatFormat = gameData.messages.meta.horse.stat_format;
Messages.BasicStatFormat = gameData.messages.meta.horse.basic_stat_format;

View file

@ -3390,6 +3390,75 @@ namespace HISP.Server
byte[] ChatPacket = PacketBuilder.CreateChat(Messages.BinocularsNothing, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(ChatPacket);
}
break;
case PacketBuilder.ITEM_CRAFT:
packetStr = Encoding.UTF8.GetString(packet);
string craftIdStr = packetStr.Substring(2, packet.Length - 2);
int craftId = 0;
// Prevent crashing on non-int string.
try
{
craftId = Int32.Parse(craftIdStr);
}
catch (FormatException)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to craft using craft id NaN.");
return;
}
if(Workshop.CraftIdExists(craftId))
{
Workshop.CraftableItem itm = Workshop.GetCraftId(craftId);
if(itm.MoneyCost <= sender.LoggedinUser.Money) // Check money
{
foreach(Workshop.RequiredItem reqItem in itm.RequiredItems)
{
if (sender.LoggedinUser.Inventory.HasItemId(reqItem.RequiredItemId))
{
if (sender.LoggedinUser.Inventory.GetItemByItemId(reqItem.RequiredItemId).ItemInstances.Count < reqItem.RequiredItemCount)
goto failMissingItem;
}
else
goto failMissingItem;
}
// Finally create the items
try
{
sender.LoggedinUser.Inventory.Add(new ItemInstance(itm.GiveItemId));
}
catch(InventoryException)
{
byte[] inventoryFullMessage = PacketBuilder.CreateChat(Messages.WorkshopNoRoomInInventory, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(inventoryFullMessage);
break;
}
sender.LoggedinUser.Money -= itm.MoneyCost;
// Remove the required items..
foreach(Workshop.RequiredItem reqItem in itm.RequiredItems)
for(int i = 0; i < reqItem.RequiredItemCount; i++)
sender.LoggedinUser.Inventory.Remove(sender.LoggedinUser.Inventory.GetItemByItemId(reqItem.RequiredItemId).ItemInstances[0]);
byte[] itemCraftSuccess = PacketBuilder.CreateChat(Messages.WorkshopCraftingSuccess, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(itemCraftSuccess);
break;
}
else
{
byte[] cantAffordMessage = PacketBuilder.CreateChat(Messages.WorkshopCannotAfford, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(cantAffordMessage);
break;
}
failMissingItem:
{
byte[] missingItemMessage = PacketBuilder.CreateChat(Messages.WorkshopMissingRequiredItem, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(missingItemMessage);
break;
}
}
break;
case PacketBuilder.ITEM_SELL: // Handles selling an item.
int totalSold = 1;

View file

@ -137,6 +137,7 @@ namespace HISP.Server
public const byte ITEM_DRINK = 0x52;
public const byte ITEM_BINOCULARS = 0x5C;
public const byte ITEM_MAGNIFYING = 0x5D;
public const byte ITEM_CRAFT = 0x64;
public const byte ITEM_RAKE = 0x5B;
public const byte ITEM_SHOVEL = 0x5A;