mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-20 03:39:16 +12:00
Fix crashing on talking to npcs with 0 chatpoints.
This commit is contained in:
parent
d776d2adc3
commit
fa8f21388c
8 changed files with 214 additions and 10 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 >-<
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue