mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-07 13:45:42 +12:00
Maybe? NPC Randomly Wander..
This commit is contained in:
parent
f20e67bfd6
commit
0767f82299
4 changed files with 124 additions and 14 deletions
|
@ -50,6 +50,14 @@ namespace HISP.Game.Chat
|
|||
try
|
||||
{
|
||||
questId = int.Parse(args[1]);
|
||||
if(args.Length >= 3)
|
||||
{
|
||||
if (args[2] == "FORCE")
|
||||
{
|
||||
Quest.CompleteQuest(user, Quest.GetQuestById(questId));
|
||||
goto msg;
|
||||
}
|
||||
}
|
||||
Quest.ActivateQuest(user, Quest.GetQuestById(questId));
|
||||
}
|
||||
catch (Exception)
|
||||
|
@ -61,6 +69,7 @@ namespace HISP.Game.Chat
|
|||
{
|
||||
return false;
|
||||
}
|
||||
msg:;
|
||||
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatAdminCommandCompleteMessage(message.Substring(1)), PacketBuilder.CHAT_BOTTOM_LEFT);
|
||||
user.LoggedinClient.SendPacket(chatPacket);
|
||||
return true;
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace HISP.Game
|
|||
|
||||
public NpcReply[] Replies;
|
||||
}
|
||||
public struct NpcEntry
|
||||
public class NpcEntry
|
||||
{
|
||||
public int Id;
|
||||
public string Name;
|
||||
|
@ -43,6 +43,95 @@ namespace HISP.Game
|
|||
public bool LibarySearchable;
|
||||
public int IconId;
|
||||
|
||||
private int udlrScriptPos = 0;
|
||||
|
||||
private bool canNpcBeHere(int x, int y)
|
||||
{
|
||||
// Horses cannot be in towns.
|
||||
if (World.InTown(x, y))
|
||||
return false;
|
||||
if (World.InSpecialTile(x, y))
|
||||
return false;
|
||||
|
||||
// Check Tile Type
|
||||
int TileID = Map.GetTileId(x, y, false);
|
||||
string TileType = Map.TerrainTiles[TileID - 1].Type;
|
||||
if (TileType != this.StayOn)
|
||||
return false;
|
||||
|
||||
if (Map.CheckPassable(x, y)) // Can the player stand over here?
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
public void RandomWander()
|
||||
{
|
||||
if(Moves)
|
||||
{
|
||||
if(UDLRStartX == 0 && UDLRStartY == 0) // not scripted.
|
||||
{
|
||||
if (GameServer.GetUsersAt(this.X, this.Y, true, true).Length > 0)
|
||||
return;
|
||||
|
||||
int direction = GameServer.RandomNumberGenerator.Next(0, 3);
|
||||
int tryX = this.X;
|
||||
int tryY = this.Y;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case 0:
|
||||
tryX += 1;
|
||||
break;
|
||||
case 1:
|
||||
tryX -= 1;
|
||||
break;
|
||||
case 2:
|
||||
tryY += 1;
|
||||
break;
|
||||
case 3:
|
||||
tryY -= 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (canNpcBeHere(tryX, tryY))
|
||||
{
|
||||
X = tryX;
|
||||
Y = tryY;
|
||||
}
|
||||
}
|
||||
else // Is Scripted.
|
||||
{
|
||||
|
||||
X = UDLRStartX;
|
||||
Y = UDLRStartY;
|
||||
for(int i = 0; i < udlrScriptPos; i++)
|
||||
{
|
||||
|
||||
switch (UDLRScript.ToLower()[i])
|
||||
{
|
||||
case 'u':
|
||||
Y++;
|
||||
break;
|
||||
case 'd':
|
||||
Y--;
|
||||
break;
|
||||
case 'l':
|
||||
X--;
|
||||
break;
|
||||
case 'r':
|
||||
X++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
udlrScriptPos++;
|
||||
|
||||
if (udlrScriptPos > UDLRScript.Length)
|
||||
udlrScriptPos = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public NpcChat[] Chatpoints;
|
||||
}
|
||||
|
||||
|
@ -123,6 +212,16 @@ namespace HISP.Game
|
|||
throw new KeyNotFoundException("Npc id: " + id + " not found!");
|
||||
}
|
||||
|
||||
public static void WanderNpcs()
|
||||
{
|
||||
Logger.DebugPrint("Making NPC's randomly wander.");
|
||||
foreach(NpcEntry npc in NpcList)
|
||||
{
|
||||
if(GameServer.RandomNumberGenerator.Next(0,100) > 50)
|
||||
npc.RandomWander();
|
||||
}
|
||||
}
|
||||
|
||||
public static NpcEntry[] GetNpcByXAndY(int x, int y)
|
||||
{
|
||||
List<NpcEntry> npcs = new List<NpcEntry>();
|
||||
|
|
|
@ -121,19 +121,19 @@ namespace HISP.Game
|
|||
|
||||
public static bool CanComplete(User user, QuestEntry quest)
|
||||
{
|
||||
// Has completed other required quests?
|
||||
foreach (int questId in quest.RequiresQuestIdCompleted)
|
||||
if (user.Quests.GetTrackedQuestAmount(questId) < 1)
|
||||
return false;
|
||||
|
||||
// Has NOT competed other MUST NOT BE required quests
|
||||
foreach (int questId in quest.RequiresQuestIdNotCompleted)
|
||||
if (user.Quests.GetTrackedQuestAmount(questId) > 1)
|
||||
return false;
|
||||
|
||||
if (quest.Tracked)
|
||||
{
|
||||
|
||||
// Has completed other required quests?
|
||||
foreach (int questId in quest.RequiresQuestIdCompleted)
|
||||
if (user.Quests.GetTrackedQuestAmount(questId) < 1)
|
||||
return false;
|
||||
|
||||
// Has NOT competed other MUST NOT BE required quests
|
||||
foreach (int questId in quest.RequiresQuestIdNotCompleted)
|
||||
if (user.Quests.GetTrackedQuestAmount(questId) > 1)
|
||||
return false;
|
||||
|
||||
// Has allready tracked this quest?
|
||||
if (user.Quests.GetTrackedQuestAmount(quest.Id) >= quest.MaxRepeats)
|
||||
return false;
|
||||
|
|
|
@ -91,6 +91,7 @@ namespace HISP.Server
|
|||
Database.IncPlayerTirednessForOfflineUsers();
|
||||
DroppedItems.Update();
|
||||
WildHorse.Update();
|
||||
Npc.WanderNpcs();
|
||||
minuteTimer.Change(oneMinute, oneMinute);
|
||||
}
|
||||
|
||||
|
@ -1169,6 +1170,7 @@ namespace HISP.Server
|
|||
catch (Exception)
|
||||
{
|
||||
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to deposit/witthdraw NaN money....");
|
||||
UpdateArea(sender);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1181,12 +1183,12 @@ namespace HISP.Server
|
|||
sender.SendPacket(chatPacket);
|
||||
}
|
||||
|
||||
if ((moneyWithdrawn >= sender.LoggedinUser.BankMoney) && moneyWithdrawn != 0)
|
||||
if ((moneyWithdrawn <= sender.LoggedinUser.BankMoney) && moneyWithdrawn != 0)
|
||||
{
|
||||
sender.LoggedinUser.BankMoney -= moneyWithdrawn;
|
||||
sender.LoggedinUser.Money += (int)moneyWithdrawn;
|
||||
sender.LoggedinUser.Money += Convert.ToInt32(moneyWithdrawn);
|
||||
|
||||
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatWithdrawMoneyMessage((int)moneyWithdrawn), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatWithdrawMoneyMessage(Convert.ToInt32(moneyWithdrawn)), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
sender.SendPacket(chatPacket);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue