Fix crashing on talking to npcs with 0 chatpoints.

This commit is contained in:
SilicaAndPina 2021-02-09 21:25:12 +13:00
parent d776d2adc3
commit fa8f21388c
8 changed files with 214 additions and 10 deletions

View file

@ -100,6 +100,11 @@
"mute_help":"Mute Channel Not Recognized. (ALL/ADS/GLOBAL/ISLAND/NEAR/HERE/BUDDY/PM/BR/SOCIALS/LOGINS)",
"player_command_completed":"<FONT COLOR='#FF0000'><B>PLAYER COMMAND [%COMMAND%] COMPLETED</B></FONT>",
"admin_command_completed":"<FONT COLOR='#FF0000'><B>COMMAND [%COMMAND%]:</B></FONT>",
"mod_isle":{
"x":165,
"y":465,
"message":"*POOF* Solitude."
}
},
"disconnect":{
"banned":"Your account has been BANNED. You will no longer be able to login",
@ -148,11 +153,15 @@
"click_message":"%USERNAME%'s %TITLE%",
"dorothy_message":"There's no place like home... There's no place like home...",
"dorothy_prison_isle":"You tap them together a bunch of times, but nothing.. They don't work here!",
"ranch_buy_cannot_afford":"You cannot afford this property!",
"ranch_brought":"You paid $%PRICE% and are now the proud owner of this ranch!",
"saved_ranch":"Saved Ranch Description.",
"default_title":"Ranch",
"ranch_description":"^PLRanch Title:|%RANCHTITLE%^LYour Ranch Description:^R1^PB160|%RANCHDESC%^PS11|SAVE DESCRIPTION",
"edit_description":"^PLRanch Title:|%RANCHTITLE%^LYour Ranch Description:^R1^PB160|%RANCHDESC%^PS11|SAVE DESCRIPTION",
"your_ranch_meta":"<B>%USERANME%'s %TITLE%</B>",
"view_desc":"^H<B>YOUR RANCH DESCRIPTION:</B><BR>%DESCRIPTION%<BR>^T5Edit Your Ranch Description^D27|DESCRIPTION^R1",
"build":{
"build_on_this_spot":"You can build one of the following buildings on this spot:",
"build_format":"^T6Build a %BUILDINGNAME% for $%PRICE%^B6L%BUILDINGID%^B6B%BUILDINGID%^R1",
@ -161,18 +170,17 @@
"build_complete":"Additional ranch building has been constructed.",
"building_allready_placed":"You already have a building here:^T6Remove the %BUILDINGNAME%^B6R%BUILDINGID%^R1^L(You will get 35% money back - $%PRICE%)^R1",
"torn_down":"You have torn down a ranch building and were refunded $%PRICE%.",
"building_Info":"This is a <B>%BUILDINGNAME%</B>.<BR>Details: %BUILDINGDESC%",
"view_building":"This is a <B>%BUILDINGNAME%</B>.<BR>Details: %BUILDINGDESC%",
"barn":"<BR>Owner's horses in barns:%HORSELIST%"
},
"upgrade":{
"upgrade_message":"Ranch Upgraded.",
"cannot_afford":"You cannot afford this upgrade!",
"upgrade_meta":"You currently have a <B>%UPGRADENAME%</B>.<BR>Details: %UPGRADEDESC%<BR>%YOUCOULDUPGRADE%^R1^LYou could also sell your ranch: (75% of total invested)^R1^T6SELL your ranch for $%SELLPRICE%^D60|SELL^R1",
"upgrade_txt":"<BR>You could upgrade to a:^T6%NEXTUPGRADE% for $%COST%^B6U"
"you_could_upgrade":"<BR>You could upgrade to a:^T6%NEXTUPGRADE% for $%COST%^B6U"
},
"your_ranch_meta":"<B>%USERANME%'s %TITLE%</B>",
"rest_here":"<BR>You have a building here to rest in. You are now fully rested.<BR>",
"special":{
"rest_here":"<BR>You have a building here to rest in. You are now fully rested.",
"grain_silo":"<BR>You have a Grain Silo. All of your horses have just been fully fed.",
"barn":"<BR>You have %COUNT% Barn(s). This provides for %AMOUNT% extra horses.",
"big_barn":".<BR>You have %COUNT% Big Barn(s). This provides for %AMOUNT% extra horses",
@ -188,7 +196,6 @@
"fully_rested":"<BR>You have a Barn. All of your horses are fully relaxed now.",
"wagon_used":"Your wagon dropped you off at the nearest station."
},
"view_desc":"^H<B>YOUR RANCH DESCRIPTION:</B><BR>%DESCRIPTION%<BR>^T5Edit Your Ranch Description^D27|DESCRIPTION^R1"
},
"riddler":{
"riddle_format":"Welcome to an Enigmatic Perplexing Conundrum!<BR>(Answer with the simplest form possible. There is no penalty for wrong answers. DO NOT discuss the riddles in Global Chat)<BR><BR><BR><B>The following Riddling Riddle Riddles you:</B><BR>%RIDDLE%^PLAnswer Riddle:|^PS6|SOLVE RIDDLE",
@ -603,6 +610,7 @@
},
"npc":{
"start_chat_format":"^I%ICONID%^T8%NAME%, %DESCRIPTION%",
"no_chatpoints":", is busy.",
"chatpoint_format":" <I>Conversation with %NAME%, %DESCRIPTION%</I><BR><BR><B>%NAME%:</B> %TEXT%",
"reply_format":"^N%TEXT%^BHB%ID%^R2",
"npc_information_format":"<B>Looking at %NAME%</B>:<BR>%DESCRIPTION%",

View file

@ -25,6 +25,9 @@ namespace HISP.Game
public static int NewUserStartX;
public static int NewUserStartY;
public static int ModIsleX;
public static int ModIsleY;
public static int GetTileId(int x, int y, bool overlay)
{
int pos = ((x * Height) + y);

View file

@ -10,6 +10,63 @@ namespace HISP.Game
public static int RequiredChatViolations;
public static int DefaultInventoryMax;
// Mod isle
public static string ModIsleMessage;
// Ranch
public static string RanchUnownedRanchFormat;
public static string RanchYouCouldPurchaseThisRanch;
public static string RanchYouAllreadyOwnARanch;
public static string RanchUnownedRanchClicked;
public static string RanchClickMessageFormat;
public static string RanchDorothyShoesMessage;
public static string RanchDorothyShoesPrisonIsleMessage;
public static string RanchCantAffordRanch;
public static string RanchRanchBroughtMessageFormat;
public static string RanchSavedRanchDescripton;
public static string RanchDefaultRanchTitle;
public static string RanchEditDescriptionMetaFormat;
public static string RanchYourRanchMetaFormat;
public static string RanchDescription;
// Ranch: Build.
public static string RanchCanBuildOneOfTheFollowingInThisSpot;
public static string RanchBuildingEntryFormat;
public static string RanchCantAffordThisBuilding;
public static string RanchBuildingInformationFormat;
public static string RanchBuildingComplete;
public static string RanchBuildingAlreadyHere;
public static string RanchTornDownRanchBuildingFormat;
public static string RanchViewBuildingFormat;
public static string RanchBarnHorsesFormat;
// Ranch: Upgrade
public static string UpgradedMessage;
public static string UpgradeCannotAfford;
public static string UpgradeCurrentUpgradeFormat;
public static string UpgradeNextUpgradeFormat;
// Ranch: Special
public static string BuildingRestHere;
public static string BuildingGrainSilo;
public static string BuildingBarnFormat;
public static string BuildingBigBarnFormat;
public static string BuildingGoldBarnFormat;
public static string BuildingWaterWell;
public static string BuildingWindmillFormat;
public static string BuildingWagon;
public static string BuildingTrainingPen;
public static string BuildingVegatableGarden;
public static string RanchTrainAllAttempt;
public static string RanchTrainSuccess;
public static string RanchTrainCantTrain;
public static string RanchHorsesFullyRested;
public static string RanchWagonDroppedYouOff;
// Tools
public static string BinocularsNothing;
public static string MagnifyNothing;
@ -461,6 +518,7 @@ namespace HISP.Game
// Npc
public static string NpcStartChatFormat;
public static string NpcNoChatpoints;
public static string NpcChatpointFormat;
public static string NpcReplyFormat;
public static string NpcInformationButton;

View file

@ -282,9 +282,16 @@ namespace HISP.Game
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);
if(ent.Chatpoints.Length > 0)
{
if (ent.LongDescription != "")
message += Messages.FormatNpcInformationButton(ent.Id);
message += Messages.FormatNpcTalkButton(ent.Id);
}
else
{
message += Messages.NpcNoChatpoints;
}
message += "^R1";
}
return message;
@ -1017,7 +1024,31 @@ namespace HISP.Game
return message;
}
private static string buildRanch(User user, int ranchId)
{
string message = "";
Ranch ranch = Ranch.GetRanchById(ranchId);
bool mine = (ranch.OwnerId == user.Id);
string swfModule = ranch.GetSwf(mine);
byte[] moduleSwf = PacketBuilder.CreateSwfModulePacket(swfModule, PacketBuilder.PACKET_SWF_MODULE_FORCE);
user.LoggedinClient.SendPacket(moduleSwf);
if (mine) // This is My DS.
{
}
else if(ranch.OwnerId == -1) // No mans sky
{
}
else
{
}
return message;
}
private static string buildWorkshop(User user)
{
Workshop shop = Workshop.GetWorkshopAt(user.X, user.Y);
@ -1176,6 +1207,10 @@ namespace HISP.Game
{
message += buildMudHole(user);
}
if(TileCode == "RANCH")
{
message += buildRanch(user, int.Parse(TileArg));
}
if(TileCode == "MULTIROOM")
{
user.MetaPriority = false; // acturally want to track updates here >-<

View file

@ -235,7 +235,7 @@ namespace HISP.Game
}
// 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)
user.Awards.AddAward(Award.GetAwardById(1)); // 25% Quest Completion Award.
if (questPointsPercent >= 50)

View file

@ -236,6 +236,22 @@ namespace HISP.Game
Database.SetRanchBuilding16(this.Id, 0);
}
}
public string GetSwf(bool mine)
{
string swf = "ranchviewer.swf?H=" + upgradedLevel.ToString();
for(int i = 0; i < buildings.Length; i++)
{
swf += "&B" + i.ToString() + "=";
if (buildings[i] != null)
{
swf += buildings[i].Id.ToString();
}
}
if (mine)
swf += "&MINE=1";
return swf;
}
public Ranch(int x, int y, int id, int value)
@ -322,6 +338,15 @@ namespace HISP.Game
}
return false;
}
public static Ranch GetRanchById(int ranchId)
{
foreach (Ranch ranch in Ranches)
{
if (ranch.Id == ranchId)
return ranch;
}
throw new KeyNotFoundException("No Ranch with id " + ranchId);
}
public static Ranch GetRanchAt(int x, int y)
{
foreach(Ranch ranch in Ranches)

View file

@ -660,6 +660,67 @@ namespace HISP.Server
Map.NewUserStartX = gameData.messages.new_user.starting_x;
Map.NewUserStartY = gameData.messages.new_user.starting_y;
// Mod Isle
Messages.ModIsleMessage = gameData.messages.commands.mod_isle.message;
Map.ModIsleX = gameData.messages.commands.mod_isle.x;
Map.ModIsleY = gameData.messages.commands.mod_isle.y;
// Ranch
Messages.RanchUnownedRanchFormat = gameData.messages.meta.ranch.unowned_ranch;
Messages.RanchYouCouldPurchaseThisRanch = gameData.messages.meta.ranch.you_could_purchase_this;
Messages.RanchYouAllreadyOwnARanch = gameData.messages.meta.ranch.ranch_already_owned;
Messages.RanchUnownedRanchClicked = gameData.messages.meta.ranch.unowned_ranch_click;
Messages.RanchClickMessageFormat = gameData.messages.meta.ranch.click_message;
Messages.RanchDorothyShoesMessage = gameData.messages.meta.ranch.dorothy_message;
Messages.RanchDorothyShoesPrisonIsleMessage = gameData.messages.meta.ranch.dorothy_prison_isle;
Messages.RanchCantAffordRanch = gameData.messages.meta.ranch.ranch_buy_cannot_afford;
Messages.RanchRanchBroughtMessageFormat = gameData.messages.meta.ranch.ranch_brought;
Messages.RanchSavedRanchDescripton = gameData.messages.meta.ranch.saved_ranch;
Messages.RanchDefaultRanchTitle = gameData.messages.meta.ranch.default_title;
Messages.RanchEditDescriptionMetaFormat = gameData.messages.meta.ranch.edit_description;
Messages.RanchYourRanchMetaFormat = gameData.messages.meta.ranch.your_ranch_meta;
Messages.RanchDescription = gameData.messages.meta.ranch.view_desc;
// Ranch : Breed
Messages.RanchCanBuildOneOfTheFollowingInThisSpot = gameData.messages.meta.ranch.build.build_on_this_spot;
Messages.RanchBuildingEntryFormat = gameData.messages.meta.ranch.build.build_format;
Messages.RanchCantAffordThisBuilding = gameData.messages.meta.ranch.build.cannot_afford;
Messages.RanchBuildingInformationFormat = gameData.messages.meta.ranch.build.information;
Messages.RanchBuildingComplete = gameData.messages.meta.ranch.build.build_complete;
Messages.RanchBuildingAlreadyHere = gameData.messages.meta.ranch.build.building_allready_placed;
Messages.RanchTornDownRanchBuildingFormat = gameData.messages.meta.ranch.build.torn_down;
Messages.RanchViewBuildingFormat = gameData.messages.meta.ranch.build.view_building;
Messages.RanchBarnHorsesFormat = gameData.messages.meta.ranch.build.barn;
// Ranch : Upgrades
Messages.UpgradedMessage = gameData.messages.meta.ranch.upgrade.upgrade_message;
Messages.UpgradeCannotAfford = gameData.messages.meta.ranch.upgrade.cannot_afford;
Messages.UpgradeCurrentUpgradeFormat = gameData.messages.meta.ranch.upgrade.upgrade_meta;
Messages.UpgradeNextUpgradeFormat = gameData.messages.meta.ranch.upgrade.you_could_upgrade;
// Ranch : Special
Messages.BuildingRestHere = gameData.messages.meta.ranch.special.rest_here;
Messages.BuildingGrainSilo = gameData.messages.meta.ranch.special.grain_silo;
Messages.BuildingBarnFormat = gameData.messages.meta.ranch.special.barn;
Messages.BuildingBigBarnFormat = gameData.messages.meta.ranch.special.big_barn;
Messages.BuildingGoldBarnFormat = gameData.messages.meta.ranch.special.gold_barn;
Messages.BuildingWaterWell = gameData.messages.meta.ranch.special.water_well;
Messages.BuildingWindmillFormat = gameData.messages.meta.ranch.special.windmills;
Messages.BuildingWagon = gameData.messages.meta.ranch.special.wagon;
Messages.BuildingTrainingPen = gameData.messages.meta.ranch.special.training_pen;
Messages.BuildingVegatableGarden = gameData.messages.meta.ranch.special.vegatable_garden;
Messages.RanchTrainAllAttempt = gameData.messages.meta.ranch.special.train_all;
Messages.RanchTrainSuccess = gameData.messages.meta.ranch.special.train_success;
Messages.RanchTrainCantTrain = gameData.messages.meta.ranch.special.train_cant_train;
Messages.RanchHorsesFullyRested = gameData.messages.meta.ranch.special.fully_rested;
Messages.RanchWagonDroppedYouOff = gameData.messages.meta.ranch.special.wagon_used;
// Treasure
Messages.PirateTreasureFormat = gameData.messages.treasure.pirate_treasure;
@ -1218,6 +1279,7 @@ namespace HISP.Server
// Npc
Messages.NpcStartChatFormat = gameData.messages.meta.npc.start_chat_format;
Messages.NpcNoChatpoints = gameData.messages.meta.npc.no_chatpoints;
Messages.NpcChatpointFormat = gameData.messages.meta.npc.chatpoint_format;
Messages.NpcReplyFormat = gameData.messages.meta.npc.reply_format;
Messages.NpcTalkButton = gameData.messages.meta.npc.npc_talk_button;

View file

@ -2745,9 +2745,22 @@ namespace HISP.Server
Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to start talking to an NPC with id that is NaN.");
return;
}
if(!Npc.NpcExists(chatId))
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to start talking to an NPC that doesnt exist.");
return;
}
sender.LoggedinUser.MetaPriority = true;
Npc.NpcEntry entry = Npc.GetNpcById(chatId);
if(entry.Chatpoints.Length <= 0)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Tried to start talking to an NPC with no chatpoints.");
return;
}
int defaultChatpointId = Npc.GetDefaultChatpoint(sender.LoggedinUser, entry);
Npc.NpcChat startingChatpoint = Npc.GetNpcChatpoint(entry, defaultChatpointId);