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

@ -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)