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

View file

@ -31,7 +31,7 @@ namespace HISP.Game.Chat
return false; return false;
} }
} }
if (args[0] == "MONEY") else if (args[0] == "MONEY")
{ {
int money = 0; int money = 0;
try try
@ -44,7 +44,7 @@ namespace HISP.Game.Chat
return false; return false;
} }
} }
if (args[0] == "QUEST") else if (args[0] == "QUEST")
{ {
int questId = 0; int questId = 0;
try try
@ -57,7 +57,10 @@ namespace HISP.Game.Chat
return false; return false;
} }
} }
else
{
return false;
}
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT); byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
user.LoggedinClient.SendPacket(chatPacket); user.LoggedinClient.SendPacket(chatPacket);
return true; return true;
@ -220,6 +223,31 @@ namespace HISP.Game.Chat
return false; 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(",")) if(args[0].Contains(","))
{ {
try try

View file

@ -217,6 +217,17 @@ namespace HISP.Game
public static string TackViewSetFormat; public static string TackViewSetFormat;
public static string TackSetPeiceFormat; 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 // Horse
public static string BreedViewerMaximumStats; public static string BreedViewerMaximumStats;
public static string AdvancedStatFormat; public static string AdvancedStatFormat;
@ -569,6 +580,19 @@ namespace HISP.Game
// Click // Click
public static string NothingInterestingHere; 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) public static string FormatDrawingRoomSaved(int slot)
{ {
return DrawingContentsSavedInSlotFormat.Replace("%SLOT%", slot.ToString("N0")); return DrawingContentsSavedInSlotFormat.Replace("%SLOT%", slot.ToString("N0"));

View file

@ -1018,6 +1018,33 @@ namespace HISP.Game
return message; 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) private static string buildVet(Vet vet, User user)
{ {
string message = ""; string message = "";
@ -1127,6 +1154,10 @@ namespace HISP.Game
{ {
message += buildPond(user); message += buildPond(user);
} }
if(TileCode == "WORKSHOP")
{
message += buildWorkshop(user);
}
if(TileCode == "MUDHOLE") if(TileCode == "MUDHOLE")
{ {
message += buildMudHole(user); message += buildMudHole(user);
@ -1535,24 +1566,26 @@ namespace HISP.Game
if (chatpoint.ActivateQuestId != 0) if (chatpoint.ActivateQuestId != 0)
{ {
Quest.QuestEntry quest = Quest.GetQuestById(chatpoint.ActivateQuestId); 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; user.MetaPriority = true;
if (quest.SetNpcChatpoint != -1) if (result.SetChatpoint != -1)
Npc.SetDefaultChatpoint(user, npc, quest.SetNpcChatpoint); Npc.SetDefaultChatpoint(user, npc, result.SetChatpoint);
if (quest.GotoNpcChatpoint != -1) if (result.GotoChatpoint != -1)
chatpoint = Npc.GetNpcChatpoint(npc,quest.GotoNpcChatpoint); chatpoint = Npc.GetNpcChatpoint(npc, result.GotoChatpoint);
if (quest.SuccessNpcChat != null) if (result.NpcChat != null)
chatpoint.ChatText = quest.SuccessNpcChat; chatpoint.ChatText = result.NpcChat;
} }
else else
{ {
if (quest.GotoNpcChatpoint != -1) if (result.GotoChatpoint != -1)
chatpoint = Npc.GetNpcChatpoint(npc, quest.GotoNpcChatpoint); chatpoint = Npc.GetNpcChatpoint(npc, result.GotoChatpoint);
if (quest.FailNpcChat != null) if (result.NpcChat != null)
chatpoint.ChatText = quest.FailNpcChat; chatpoint.ChatText = result.NpcChat;
if (quest.HideReplyOnFail) if (result.HideRepliesOnFail)
hideReplys = true; hideReplys = true;
} }
} }

View file

@ -102,6 +102,23 @@ namespace HISP.Game
return sortedQuests.ToArray(); 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) public static bool CanComplete(User user, QuestEntry quest)
{ {
if (quest.Tracked) if (quest.Tracked)
@ -153,8 +170,10 @@ namespace HISP.Game
return true; 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 // Take Items
foreach (QuestItemInfo itemInfo in quest.ItemsRequired) foreach (QuestItemInfo itemInfo in quest.ItemsRequired)
{ {
@ -181,12 +200,24 @@ namespace HISP.Game
// Give quest points // Give quest points
user.QuestPoints += quest.QuestPointsEarned; 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) if (quest.Tracked)
user.Quests.TrackQuest(quest.Id); user.Quests.TrackQuest(quest.Id);
if (quest.ChainedQuestId != 0) if (quest.ChainedQuestId != 0)
ActivateQuest(user, Quest.GetQuestById(quest.ChainedQuestId), npcActivation); res = ActivateQuest(user, Quest.GetQuestById(quest.ChainedQuestId), npcActivation, res);
if (quest.SuccessMessage != null) if (quest.SuccessMessage != null)
{ {
@ -203,9 +234,6 @@ namespace HISP.Game
} }
} }
// Check if award unlocked // Check if award unlocked
int questPointsPercent = Convert.ToInt32(Math.Floor(((decimal)user.QuestPoints / (decimal)GetTotalQuestPoints()) * (decimal)100.0)); int questPointsPercent = Convert.ToInt32(Math.Floor(((decimal)user.QuestPoints / (decimal)GetTotalQuestPoints()) * (decimal)100.0));
if (questPointsPercent >= 25) if (questPointsPercent >= 25)
@ -224,10 +252,23 @@ namespace HISP.Game
user.LoggedinClient.SendPacket(swfLoadPacket); 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 (quest.FailNpcChat != null)
{ {
if (!npcActivation) if (!npcActivation)
@ -235,19 +276,24 @@ namespace HISP.Game
byte[] ChatPacket = PacketBuilder.CreateChat(quest.FailNpcChat, PacketBuilder.CHAT_BOTTOM_RIGHT); byte[] ChatPacket = PacketBuilder.CreateChat(quest.FailNpcChat, PacketBuilder.CHAT_BOTTOM_RIGHT);
user.LoggedinClient.SendPacket(ChatPacket); 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)) if (CanComplete(user, quest))
{ {
return CompleteQuest(user, quest, npcActivation); return CompleteQuest(user, quest, npcActivation, res);
} }
else 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 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) public static CraftableItem GetCraftId(int id)
{ {
foreach(Workshop wkShop in Workshops) 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.GiveItemId = gameData.workshop[i].craftable_items[ii].give_item;
craftableItem.MoneyCost = gameData.workshop[i].craftable_items[ii].money_cost; craftableItem.MoneyCost = gameData.workshop[i].craftable_items[ii].money_cost;
int totalItemsRequired = gameData.workshop[i].craftable_items[ii].required_items.Count; 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(); Workshop.RequiredItem requiredItem = new Workshop.RequiredItem();
requiredItem.RequiredItemId = totalItemsRequired = gameData.workshop[i].craftable_items[ii].required_items[iii].req_item; requiredItem.RequiredItemId = 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.RequiredItemCount = gameData.workshop[i].craftable_items[ii].required_items[iii].req_quantity;
craftableItem.RequiredItems.Add(requiredItem); craftableItem.RequiredItems.Add(requiredItem);
} }
wkShop.CraftableItems.Add(craftableItem); wkShop.CraftableItems.Add(craftableItem);
@ -761,6 +761,17 @@ namespace HISP.Server
Messages.BankDepositedMoneyFormat = gameData.messages.bank.deposit_format; Messages.BankDepositedMoneyFormat = gameData.messages.bank.deposit_format;
Messages.BankWithdrewMoneyFormat = gameData.messages.bank.withdraw_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 // Horses
Messages.AdvancedStatFormat = gameData.messages.meta.horse.stat_format; Messages.AdvancedStatFormat = gameData.messages.meta.horse.stat_format;
Messages.BasicStatFormat = gameData.messages.meta.horse.basic_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); byte[] ChatPacket = PacketBuilder.CreateChat(Messages.BinocularsNothing, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(ChatPacket); 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; break;
case PacketBuilder.ITEM_SELL: // Handles selling an item. case PacketBuilder.ITEM_SELL: // Handles selling an item.
int totalSold = 1; int totalSold = 1;

View file

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