mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-21 12:19:15 +12:00
add simple jumping arena and advanced jumping arena,
This commit is contained in:
parent
934a737613
commit
8f0ed68110
10 changed files with 859 additions and 78 deletions
351
Horse Isle Server/HorseIsleServer/Game/Arena.cs
Normal file
351
Horse Isle Server/HorseIsleServer/Game/Arena.cs
Normal file
|
@ -0,0 +1,351 @@
|
|||
using HISP.Game.Horse;
|
||||
using HISP.Player;
|
||||
using HISP.Security;
|
||||
using HISP.Server;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HISP.Game
|
||||
{
|
||||
public class Arena
|
||||
{
|
||||
public class ArenaEntry
|
||||
{
|
||||
public User EnteredUser;
|
||||
public HorseInstance EnteredHorse;
|
||||
public int SubmitScore = 0;
|
||||
public bool Done = false;
|
||||
}
|
||||
public static List<Arena> Arenas = new List<Arena>();
|
||||
public Arena(int id, string type, int entryCost, int raceEvery, int slots, int timeOut)
|
||||
{
|
||||
RandomId = RandomID.NextRandomId();
|
||||
Mode = "TAKINGENTRIES";
|
||||
Id = id;
|
||||
Type = type;
|
||||
EntryCost = entryCost;
|
||||
RaceEvery = raceEvery;
|
||||
Slots = slots;
|
||||
Timeout = timeOut;
|
||||
Arenas.Add(this);
|
||||
Entries = new List<ArenaEntry>();
|
||||
}
|
||||
public int Id;
|
||||
public string Type;
|
||||
public int EntryCost;
|
||||
public int RandomId;
|
||||
public int RaceEvery;
|
||||
public int Slots;
|
||||
public string Mode;
|
||||
public int Timeout;
|
||||
public List<ArenaEntry> Entries;
|
||||
private Timer arenaTimeout;
|
||||
|
||||
public bool HaveAllPlayersCompleted()
|
||||
{
|
||||
int playersCompleted = 0;
|
||||
foreach(ArenaEntry entry in Entries.ToArray())
|
||||
{
|
||||
if (entry.Done)
|
||||
playersCompleted++;
|
||||
}
|
||||
if (playersCompleted >= Entries.Count)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public void SubmitScore(User user, int score)
|
||||
{
|
||||
foreach(ArenaEntry entry in Entries)
|
||||
{
|
||||
if(entry.EnteredUser.Id == user.Id)
|
||||
{
|
||||
entry.SubmitScore = score;
|
||||
entry.Done = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (HaveAllPlayersCompleted())
|
||||
End();
|
||||
}
|
||||
private string getSwf(ArenaEntry entry)
|
||||
{
|
||||
HorseInfo.StatCalculator speedCalculator = new HorseInfo.StatCalculator(entry.EnteredHorse, HorseInfo.StatType.SPEED, entry.EnteredUser);
|
||||
HorseInfo.StatCalculator strengthCalculator = new HorseInfo.StatCalculator(entry.EnteredHorse, HorseInfo.StatType.STRENGTH, entry.EnteredUser);
|
||||
HorseInfo.StatCalculator enduranceCalculator = new HorseInfo.StatCalculator(entry.EnteredHorse, HorseInfo.StatType.ENDURANCE, entry.EnteredUser);
|
||||
HorseInfo.StatCalculator conformationCalculator = new HorseInfo.StatCalculator(entry.EnteredHorse, HorseInfo.StatType.CONFORMATION, entry.EnteredUser);
|
||||
|
||||
switch (Type)
|
||||
{
|
||||
case "BEGINNERJUMPING":
|
||||
int bigJumps = Convert.ToInt32(Math.Round((double)strengthCalculator.Total / 100.0))+1;
|
||||
return "jumpingarena1.swf?BIGJUMPS="+bigJumps+"&SPEEEDMAX="+speedCalculator.Total+"&JUNK=";
|
||||
case "JUMPING":
|
||||
int bonus = entry.EnteredHorse.BasicStats.Health + entry.EnteredHorse.BasicStats.Hunger + entry.EnteredHorse.BasicStats.Thirst + entry.EnteredHorse.BasicStats.Shoes;
|
||||
return "jumpingarena2.swf?BONUS=" + bonus + "&STRENGTH=" + strengthCalculator.Total + "&SPEED=" + speedCalculator.Total + "&ENDURANCE=" + enduranceCalculator.Total + "&JUNK=";
|
||||
case "CONFORMATION":
|
||||
int baseScore = conformationCalculator.Total + ((entry.EnteredHorse.BasicStats.Groom > 750) ? 1000 : 500);
|
||||
int pos = GetUserPos(entry.EnteredUser);
|
||||
string swf = "dressagearena.swf?BASESCORE=" + baseScore;
|
||||
int i = 1;
|
||||
foreach (ArenaEntry ent in Entries.ToArray())
|
||||
swf += "&HN" + i.ToString() + "=" + ent.EnteredUser.Username;
|
||||
swf += "&POS="+pos+"&JUNK=";
|
||||
return swf;
|
||||
case "DRAFT":
|
||||
int draftAbility = Convert.ToInt32(Math.Round((((double)entry.EnteredHorse.BasicStats.Health * 2.0 + (double)entry.EnteredHorse.BasicStats.Shoes * 2.0) + (double)entry.EnteredHorse.BasicStats.Hunger + (double)entry.EnteredHorse.BasicStats.Thirst) / 6.0 + (double)strengthCalculator.Total + ((double)enduranceCalculator.Total / 2.0)));
|
||||
pos = GetUserPos(entry.EnteredUser);
|
||||
swf = "draftarena.swf?DRAFTABILITY=" + draftAbility;
|
||||
i = 1;
|
||||
foreach (ArenaEntry ent in Entries.ToArray())
|
||||
swf += "&HN" + i.ToString() + "=" + ent.EnteredUser.Username;
|
||||
swf += "&POS="+pos+"&J=";
|
||||
return swf;
|
||||
case "RACING":
|
||||
int baseSpeed = Convert.ToInt32(Math.Round((((double)entry.EnteredHorse.BasicStats.Health * 2.0 + (double)entry.EnteredHorse.BasicStats.Shoes * 2.0) + (double)entry.EnteredHorse.BasicStats.Hunger + (double)entry.EnteredHorse.BasicStats.Thirst) / 6.0 + (double)speedCalculator.Total));
|
||||
pos = GetUserPos(entry.EnteredUser);
|
||||
swf = "racingarena.swf?BASESPEED=" + baseSpeed + "&ENDURANCE=" + enduranceCalculator.Total;
|
||||
i = 1;
|
||||
foreach (ArenaEntry ent in Entries.ToArray())
|
||||
swf += "&HN" + i.ToString() + "=" + ent.EnteredUser.Username;
|
||||
swf += "&POS=" + pos + "&JUNK=";
|
||||
return swf;
|
||||
default:
|
||||
return "test.swf";
|
||||
}
|
||||
|
||||
}
|
||||
public int GetUserPos(User user)
|
||||
{
|
||||
int pos = 0;
|
||||
foreach (ArenaEntry entry in Entries.ToArray())
|
||||
{
|
||||
pos++;
|
||||
if (entry.EnteredUser.Id != user.Id)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return pos;
|
||||
}
|
||||
public void Start()
|
||||
{
|
||||
if(Entries.Count <= 0)
|
||||
{
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
Mode = "COMPETING";
|
||||
foreach(ArenaEntry entry in Entries.ToArray())
|
||||
{
|
||||
string swf = getSwf(entry);
|
||||
string message = "";
|
||||
switch (Type)
|
||||
{
|
||||
case "RACING":
|
||||
entry.EnteredHorse.BasicStats.Hunger -= 200;
|
||||
entry.EnteredHorse.BasicStats.Thirst -= 200;
|
||||
entry.EnteredHorse.BasicStats.Tiredness -= 200;
|
||||
entry.EnteredHorse.BasicStats.Shoes -= 100;
|
||||
message = Messages.ArenaRacingStartup;
|
||||
break;
|
||||
case "DRAFT":
|
||||
entry.EnteredHorse.BasicStats.Hunger -= 200;
|
||||
entry.EnteredHorse.BasicStats.Thirst -= 200;
|
||||
entry.EnteredHorse.BasicStats.Tiredness -= 200;
|
||||
entry.EnteredHorse.BasicStats.Shoes -= 100;
|
||||
message = Messages.ArenaDraftStartup;
|
||||
break;
|
||||
case "BEGINNERJUMPING":
|
||||
entry.EnteredHorse.BasicStats.Hunger -= 200;
|
||||
entry.EnteredHorse.BasicStats.Thirst -= 200;
|
||||
entry.EnteredHorse.BasicStats.Tiredness -= 200;
|
||||
entry.EnteredHorse.BasicStats.Shoes -= 100;
|
||||
message = Messages.ArenaJumpingStartup;
|
||||
break;
|
||||
case "JUMPING":
|
||||
entry.EnteredHorse.BasicStats.Hunger -= 300;
|
||||
entry.EnteredHorse.BasicStats.Thirst -= 300;
|
||||
entry.EnteredHorse.BasicStats.Tiredness -= 300;
|
||||
entry.EnteredHorse.BasicStats.Shoes -= 100;
|
||||
message = Messages.ArenaJumpingStartup;
|
||||
break;
|
||||
case "DRESSAGE":
|
||||
entry.EnteredHorse.BasicStats.Mood -= 300;
|
||||
entry.EnteredHorse.BasicStats.Tiredness -= 200;
|
||||
message = Messages.ArenaConformationStartup;
|
||||
break;
|
||||
}
|
||||
byte[] startingUpEventPacket = PacketBuilder.CreateChat(message, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
byte[] swfModulePacket = PacketBuilder.CreateSwfModulePacket(swf, PacketBuilder.PACKET_SWF_CUTSCENE);
|
||||
entry.EnteredUser.LoggedinClient.SendPacket(swfModulePacket);
|
||||
entry.EnteredUser.LoggedinClient.SendPacket(startingUpEventPacket);
|
||||
}
|
||||
|
||||
arenaTimeout = new Timer(new TimerCallback(ArenaTimedOut), null, Timeout * 60 * 1000, Timeout * 60 * 1000);
|
||||
|
||||
foreach(World.SpecialTile tile in World.SpecialTiles)
|
||||
{
|
||||
if (tile.Code == null)
|
||||
continue;
|
||||
if(tile.Code.StartsWith("ARENA-"))
|
||||
{
|
||||
string arenaId = tile.Code.Split('-')[1];
|
||||
int id = int.Parse(arenaId);
|
||||
if (id == this.Id)
|
||||
GameServer.UpdateAreaForAll(tile.X, tile.Y, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ArenaTimedOut(object state)
|
||||
{
|
||||
End();
|
||||
}
|
||||
|
||||
private void reset()
|
||||
{
|
||||
// Delete all entries
|
||||
Entries.Clear();
|
||||
RandomId = RandomID.NextRandomId();
|
||||
Mode = "TAKINGENTRIES";
|
||||
if (arenaTimeout != null)
|
||||
arenaTimeout.Dispose();
|
||||
arenaTimeout = null;
|
||||
}
|
||||
public void End()
|
||||
{
|
||||
|
||||
if(Mode == "COMPETING")
|
||||
{
|
||||
string chatMessage = Messages.ArenaResultsMessage;
|
||||
|
||||
string[] avaliblePlacings = new string[6] { Messages.ArenaFirstPlace, Messages.ArenaSecondPlace, Messages.ArenaThirdPlace, Messages.ArenaFourthPlace, Messages.ArenaFifthPlace, Messages.ArenaSixthPlace };
|
||||
|
||||
int[] expRewards = new int[Entries.Count];
|
||||
expRewards[0] = 1;
|
||||
int expAwardMul = 1;
|
||||
for(int i = 1; i < Entries.Count; i++)
|
||||
{
|
||||
expRewards[i] = 2 * expAwardMul;
|
||||
|
||||
if (expAwardMul == 1)
|
||||
expAwardMul = 2;
|
||||
else
|
||||
expAwardMul += 2;
|
||||
}
|
||||
|
||||
expRewards = expRewards.ToArray().Reverse().ToArray();
|
||||
|
||||
int place = 0;
|
||||
ArenaEntry[] winners = Entries.OrderByDescending(o => o.SubmitScore).ToArray();
|
||||
foreach (ArenaEntry entry in winners)
|
||||
{
|
||||
string placing = avaliblePlacings[place % avaliblePlacings.Length];
|
||||
|
||||
chatMessage += Messages.FormatArenaPlacing(placing, entry.EnteredUser.Username, entry.SubmitScore);
|
||||
place++;
|
||||
}
|
||||
place = 0;
|
||||
foreach(ArenaEntry entry in winners)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] arenaResults = PacketBuilder.CreateChat(chatMessage, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
entry.EnteredUser.LoggedinClient.SendPacket(arenaResults);
|
||||
|
||||
int expReward = expRewards[place];
|
||||
|
||||
entry.EnteredHorse.BasicStats.Experience += expReward;
|
||||
entry.EnteredUser.Experience += expReward;
|
||||
|
||||
if (place == 0) // WINNER!
|
||||
{
|
||||
int prize = EntryCost * Entries.Count;
|
||||
entry.EnteredUser.Money += prize;
|
||||
|
||||
byte[] youWinMessage = PacketBuilder.CreateChat(Messages.FormatArenaYouWinMessage(prize, expReward), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
entry.EnteredUser.LoggedinClient.SendPacket(youWinMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] youDONTWinMessage = PacketBuilder.CreateChat(Messages.FormatArenaOnlyWinnerWinsMessage(expReward), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
entry.EnteredUser.LoggedinClient.SendPacket(youDONTWinMessage);
|
||||
}
|
||||
place++;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
reset();
|
||||
}
|
||||
public void DeleteEntry(User user)
|
||||
{
|
||||
if (Mode == "COMPETING")
|
||||
return;
|
||||
|
||||
foreach(ArenaEntry entry in Entries)
|
||||
if(entry.EnteredUser.Id == user.Id)
|
||||
{
|
||||
Entries.Remove(entry);
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void AddEntry(User user, Horse.HorseInstance horse)
|
||||
{
|
||||
ArenaEntry arenaEntry = new ArenaEntry();
|
||||
arenaEntry.EnteredUser = user;
|
||||
arenaEntry.EnteredHorse = horse;
|
||||
Entries.Add(arenaEntry);
|
||||
}
|
||||
|
||||
public static Arena GetArenaUserEnteredIn(User user)
|
||||
{
|
||||
foreach (Arena arena in Arenas)
|
||||
if (arena.UserHasHorseEntered(user))
|
||||
return arena;
|
||||
throw new KeyNotFoundException("user was not entered in any arena.");
|
||||
}
|
||||
public bool UserHasHorseEntered(User user)
|
||||
{
|
||||
foreach (ArenaEntry entry in Entries.ToArray())
|
||||
if (entry.EnteredUser.Id == user.Id)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void StartArenas(int minutes)
|
||||
{
|
||||
foreach(Arena arena in Arenas)
|
||||
{
|
||||
if (minutes % arena.RaceEvery == 0)
|
||||
arena.Start();
|
||||
}
|
||||
|
||||
}
|
||||
public static bool UserHasEnteredHorseInAnyArena(User user)
|
||||
{
|
||||
foreach (Arena arena in Arenas)
|
||||
if (arena.UserHasHorseEntered(user))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public static Arena GetAreaById(int id)
|
||||
{
|
||||
foreach (Arena arena in Arenas)
|
||||
if (arena.Id == id)
|
||||
return arena;
|
||||
throw new KeyNotFoundException("Arena with id " + id + " NOT FOUND!");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ using HISP.Game.Items;
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using HISP.Player;
|
||||
|
||||
namespace HISP.Game.Horse
|
||||
{
|
||||
|
@ -20,14 +21,15 @@ namespace HISP.Game.Horse
|
|||
}
|
||||
public class StatCalculator
|
||||
{
|
||||
public StatCalculator(HorseInstance horse, StatType type)
|
||||
public StatCalculator(HorseInstance horse, StatType type, User user=null)
|
||||
{
|
||||
baseHorse = horse;
|
||||
horseStat = type;
|
||||
baseUser = user;
|
||||
}
|
||||
private StatType horseStat;
|
||||
private HorseInstance baseHorse;
|
||||
|
||||
private User baseUser;
|
||||
public int BaseValue
|
||||
{
|
||||
get
|
||||
|
@ -119,6 +121,31 @@ namespace HISP.Game.Horse
|
|||
}
|
||||
}
|
||||
}
|
||||
public int CompetitionGearOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
if(baseUser != null)
|
||||
{
|
||||
int offsetBy = 0;
|
||||
if(baseUser.EquipedCompetitionGear.Head != null)
|
||||
offsetBy += getOffsetFrom(baseUser.EquipedCompetitionGear.Head);
|
||||
if (baseUser.EquipedCompetitionGear.Body != null)
|
||||
offsetBy += getOffsetFrom(baseUser.EquipedCompetitionGear.Body);
|
||||
if (baseUser.EquipedCompetitionGear.Legs != null)
|
||||
offsetBy += getOffsetFrom(baseUser.EquipedCompetitionGear.Legs);
|
||||
if (baseUser.EquipedCompetitionGear.Feet != null)
|
||||
offsetBy += getOffsetFrom(baseUser.EquipedCompetitionGear.Feet);
|
||||
return offsetBy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public int CompanionOffset
|
||||
{
|
||||
get
|
||||
|
@ -149,7 +176,7 @@ namespace HISP.Game.Horse
|
|||
{
|
||||
get
|
||||
{
|
||||
return BreedValue + CompanionOffset + TackOffset;
|
||||
return BreedValue + CompanionOffset + TackOffset + CompetitionGearOffset;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -414,10 +441,13 @@ namespace HISP.Game.Horse
|
|||
}
|
||||
set
|
||||
{
|
||||
// Lol turns out pinto forgot to do this and u can have negative mood :D
|
||||
/*
|
||||
if (value > 1000)
|
||||
value = 1000;
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
*/
|
||||
mood = value;
|
||||
Database.SetHorseMood(baseHorse.RandomId, value);
|
||||
}
|
||||
|
|
|
@ -16,10 +16,57 @@ namespace HISP.Game
|
|||
// Click
|
||||
public static string PlayerHereFormat;
|
||||
|
||||
// Hammock
|
||||
public static string HammockText;
|
||||
|
||||
// Horse Games
|
||||
public static string HorseGamesSelectHorse;
|
||||
public static string HorseGamesHorseEntryFormat;
|
||||
|
||||
// Competitions
|
||||
public static string ArenaResultsMessage;
|
||||
public static string ArenaPlacingFormat;
|
||||
|
||||
public static string ArenaFirstPlace;
|
||||
public static string ArenaSecondPlace;
|
||||
public static string ArenaThirdPlace;
|
||||
public static string ArenaFourthPlace;
|
||||
public static string ArenaFifthPlace;
|
||||
public static string ArenaSixthPlace;
|
||||
|
||||
public static string ArenaEnteredInto;
|
||||
|
||||
public static string ArenaAlreadyEntered;
|
||||
public static string ArenaCantAfford;
|
||||
|
||||
public static string ArenaYourScoreFormat;
|
||||
|
||||
public static string ArenaJumpingStartup;
|
||||
public static string ArenaDraftStartup;
|
||||
public static string ArenaRacingStartup;
|
||||
public static string ArenaConformationStartup;
|
||||
|
||||
public static string ArenaYouWinFormat;
|
||||
public static string ArenaOnlyWinnerWins;
|
||||
|
||||
public static string ArenaTooHungry;
|
||||
public static string ArenaTooThirsty;
|
||||
public static string ArenaNeedsFarrier;
|
||||
public static string ArenaTooTired;
|
||||
public static string ArenaNeedsVet;
|
||||
|
||||
public static string ArenaEventNameFormat;
|
||||
|
||||
public static string ArenaCurrentlyTakingEntriesFormat;
|
||||
public static string ArenaCompetitionInProgress;
|
||||
public static string ArenaYouHaveHorseEntered;
|
||||
public static string ArenaCompetitionFull;
|
||||
|
||||
public static string ArenaEnterHorseFormat;
|
||||
public static string ArenaCurrentCompetitors;
|
||||
public static string ArenaCompetingHorseFormat;
|
||||
|
||||
|
||||
// City Hall
|
||||
public static string CityHallMenu;
|
||||
public static string CityHallMailSendMeta;
|
||||
|
@ -795,6 +842,38 @@ namespace HISP.Game
|
|||
|
||||
// Click
|
||||
public static string NothingInterestingHere;
|
||||
public static string FormatArenaCompetingHorseEntry(string userName, string horseName, int horseRandomId)
|
||||
{
|
||||
return ArenaCompetingHorseFormat.Replace("%USERNAME%", userName).Replace("%HORSENAME%", horseName).Replace("%HORSERANDOMID%", horseRandomId.ToString());
|
||||
}
|
||||
public static string FormatArenaEnterHorseButton(string horseName, int entryCost, int horseRandomId)
|
||||
{
|
||||
return ArenaEnterHorseFormat.Replace("%HORSENAME%", horseName).Replace("%ENTRYCOST%", entryCost.ToString("N0", CultureInfo.InvariantCulture)).Replace("%HORSERANDOMID%", horseRandomId.ToString());
|
||||
}
|
||||
public static string FormatArenaCurrentlyTakingEntries(int hour, int minute, string amOrPm, int timeUntil)
|
||||
{
|
||||
return ArenaCurrentlyTakingEntriesFormat.Replace("%HOUR%", hour.ToString()).Replace("%MINUTE%", minute.ToString("00")).Replace("%AMORPM%", amOrPm).Replace("%TIMEUNTIL%", timeUntil.ToString());
|
||||
}
|
||||
public static string FormatArenaEventName(string eventName)
|
||||
{
|
||||
return ArenaEventNameFormat.Replace("%EVENTNAME%", eventName);
|
||||
}
|
||||
public static string FormatArenaOnlyWinnerWinsMessage(int experience)
|
||||
{
|
||||
return ArenaOnlyWinnerWins.Replace("%EXP%", experience.ToString("N0", CultureInfo.InvariantCulture));
|
||||
}
|
||||
public static string FormatArenaYouWinMessage(int prizeMoney, int experience)
|
||||
{
|
||||
return ArenaYouWinFormat.Replace("%PRIZE%", prizeMoney.ToString("N0", CultureInfo.InvariantCulture)).Replace("%EXP%", experience.ToString("N0", CultureInfo.InvariantCulture));
|
||||
}
|
||||
public static string FormatArenaYourScore(int score)
|
||||
{
|
||||
return ArenaYourScoreFormat.Replace("%SCORE%", score.ToString("N0", CultureInfo.InvariantCulture));
|
||||
}
|
||||
public static string FormatArenaPlacing(string place, string playerName, int score)
|
||||
{
|
||||
return ArenaPlacingFormat.Replace("%PLACE%", place).Replace("%USERNAME%", playerName).Replace("%SCORE%", score.ToString("N0", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
public static string FormatHorseGamesEntry(int placing, string horseName, string Swf)
|
||||
{
|
||||
|
|
|
@ -1239,7 +1239,7 @@ namespace HISP.Game
|
|||
string message = Messages.CityHallTop25Ranches;
|
||||
int total = 1;
|
||||
|
||||
foreach(Ranch ranch in Ranch.Ranches.OrderBy(o => o.InvestedMoney).Reverse().ToList())
|
||||
foreach(Ranch ranch in Ranch.Ranches.OrderByDescending(o => o.InvestedMoney).ToList())
|
||||
{
|
||||
if (ranch.OwnerId == -1)
|
||||
continue;
|
||||
|
@ -1264,13 +1264,15 @@ namespace HISP.Game
|
|||
HorseInstance[] horses = Database.GetCheapestHorseAutoSell();
|
||||
foreach(HorseInstance horse in horses)
|
||||
{
|
||||
message += Messages.FormatCityHallCheapAutoSellEntry(horse.AutoSell, Database.GetUsername(horse.Owner), horse.Name, horse.Color, horse.Breed.Name, horse.BasicStats.Experience);
|
||||
if(horse.AutoSell > 0)
|
||||
message += Messages.FormatCityHallCheapAutoSellEntry(horse.AutoSell, Database.GetUsername(horse.Owner), horse.Name, horse.Color, horse.Breed.Name, horse.BasicStats.Experience);
|
||||
}
|
||||
message += Messages.CityHallMostExpAutoSells;
|
||||
horses = Database.GetBiggestExpAutoSell();
|
||||
foreach (HorseInstance horse in horses)
|
||||
{
|
||||
message += Messages.FormatCityHallBestExpAutoSellEntry(horse.BasicStats.Experience, Database.GetUsername(horse.Owner), horse.Name, horse.AutoSell, horse.Color, horse.Breed.Name);
|
||||
if(horse.AutoSell > 0)
|
||||
message += Messages.FormatCityHallBestExpAutoSellEntry(horse.BasicStats.Experience, Database.GetUsername(horse.Owner), horse.Name, horse.AutoSell, horse.Color, horse.Breed.Name);
|
||||
}
|
||||
message += Messages.BackToMap;
|
||||
message += Messages.MetaTerminator;
|
||||
|
@ -2230,6 +2232,62 @@ namespace HISP.Game
|
|||
message += Messages.MetaTerminator;
|
||||
return message;
|
||||
}
|
||||
private static string buildArena(User user, Arena arena)
|
||||
{
|
||||
string message = Messages.FormatArenaEventName(arena.Type);
|
||||
if(arena.Mode == "TAKINGENTRIES")
|
||||
{
|
||||
int minutes = World.ServerTime.Minutes % 60;
|
||||
|
||||
int lastMinutes = minutes - (minutes % arena.RaceEvery);
|
||||
int lastHours = (lastMinutes / 60);
|
||||
|
||||
string amOrPm = "am";
|
||||
if (lastHours == 0)
|
||||
{
|
||||
amOrPm = "am";
|
||||
lastHours = 12;
|
||||
}
|
||||
if (lastHours > 12)
|
||||
{
|
||||
lastHours -= 12;
|
||||
amOrPm = "pm";
|
||||
}
|
||||
|
||||
message += Messages.FormatArenaCurrentlyTakingEntries(lastHours, lastMinutes, amOrPm, arena.RaceEvery - minutes);
|
||||
if (arena.Entries.Count > arena.Slots)
|
||||
{
|
||||
message += Messages.ArenaCompetitionFull;
|
||||
}
|
||||
else if (!arena.UserHasHorseEntered(user))
|
||||
{
|
||||
|
||||
foreach(HorseInstance horseInstance in user.HorseInventory.HorseList)
|
||||
{
|
||||
if(horseInstance.Equipment.Saddle != null && horseInstance.Equipment.SaddlePad != null && horseInstance.Equipment.Bridle != null)
|
||||
message += Messages.FormatArenaEnterHorseButton(horseInstance.Name, arena.EntryCost, horseInstance.RandomId);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
message += Messages.ArenaYouHaveHorseEntered;
|
||||
}
|
||||
|
||||
}
|
||||
else if(arena.Mode == "COMPETING")
|
||||
{
|
||||
message += Messages.ArenaCompetitionInProgress;
|
||||
}
|
||||
|
||||
message += Messages.ArenaCurrentCompetitors;
|
||||
foreach(Arena.ArenaEntry entries in arena.Entries)
|
||||
{
|
||||
message += Messages.FormatArenaCompetingHorseEntry(entries.EnteredUser.Username, entries.EnteredHorse.Name, entries.EnteredHorse.RandomId);
|
||||
}
|
||||
message += Messages.ExitThisPlace;
|
||||
message += Messages.MetaTerminator;
|
||||
return message;
|
||||
}
|
||||
public static string BuildSpecialTileInfo(User user, World.SpecialTile specialTile)
|
||||
{
|
||||
string message = "";
|
||||
|
@ -2328,6 +2386,10 @@ namespace HISP.Game
|
|||
{
|
||||
message += buildRiddlerRiddle(user);
|
||||
}
|
||||
if(TileCode == "ARENA")
|
||||
{
|
||||
message += buildArena(user, Arena.GetAreaById(int.Parse(TileArg)));
|
||||
}
|
||||
if(TileCode == "TRAINER")
|
||||
{
|
||||
message += buildTrainer(user, Trainer.GetTrainerById(int.Parse(TileArg)));
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HISP.Player;
|
||||
using HISP.Server;
|
||||
|
||||
|
@ -155,9 +156,16 @@ namespace HISP.Game
|
|||
}
|
||||
|
||||
|
||||
public struct Time
|
||||
public class Time
|
||||
{
|
||||
public int Minutes;
|
||||
public double PreciseMinutes;
|
||||
public int Minutes
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToInt32(Math.Floor(PreciseMinutes));
|
||||
}
|
||||
}
|
||||
public int Days;
|
||||
public int Years;
|
||||
}
|
||||
|
@ -189,42 +197,18 @@ namespace HISP.Game
|
|||
|
||||
public static void TickWorldClock()
|
||||
{
|
||||
ServerTime.Minutes += 1;
|
||||
|
||||
int hours = ServerTime.Minutes / 60;
|
||||
|
||||
// Periodically write time to database:
|
||||
if (ServerTime.Minutes % 10 == 0) // every 10-in-game minutes)
|
||||
Database.SetServerTime(ServerTime.Minutes, ServerTime.Days, ServerTime.Years);
|
||||
|
||||
// Ranch Windmill Payments
|
||||
if(ServerTime.Minutes % 720 == 0) // every 12 hours
|
||||
{
|
||||
Logger.DebugPrint("Paying windmill owners . . . ");
|
||||
foreach (Ranch ranch in Ranch.Ranches)
|
||||
{
|
||||
int ranchOwner = ranch.OwnerId;
|
||||
if (ranchOwner != -1)
|
||||
{
|
||||
int moneyToAdd = 5000 * ranch.GetBuildingCount(8); // Windmill
|
||||
if (GameServer.IsUserOnline(ranchOwner))
|
||||
GameServer.GetUserById(ranchOwner).Money += moneyToAdd;
|
||||
else
|
||||
Database.SetPlayerMoney(Database.GetPlayerMoney(ranchOwner) + moneyToAdd, ranchOwner);
|
||||
}
|
||||
}
|
||||
}
|
||||
ServerTime.PreciseMinutes += 0.1;
|
||||
|
||||
|
||||
if (hours == 24) // 1 day
|
||||
if (ServerTime.Minutes > 1440) // 1 day
|
||||
{
|
||||
ServerTime.Days += 1;
|
||||
ServerTime.Minutes = 0;
|
||||
ServerTime.PreciseMinutes = 0.0;
|
||||
|
||||
Database.DoIntrestPayments(ConfigReader.IntrestRate);
|
||||
}
|
||||
|
||||
if (ServerTime.Days == 366) // 1 year!
|
||||
if (ServerTime.Days > 365) // 1 year!
|
||||
{
|
||||
ServerTime.Days = 0;
|
||||
ServerTime.Years += 1;
|
||||
|
@ -234,7 +218,7 @@ namespace HISP.Game
|
|||
public static void ReadWorldData()
|
||||
{
|
||||
Logger.DebugPrint("Reading time from database...");
|
||||
ServerTime.Minutes = Database.GetServerTime();
|
||||
ServerTime.PreciseMinutes = Database.GetServerTime();
|
||||
ServerTime.Days = Database.GetServerDay();
|
||||
ServerTime.Years = Database.GetServerYear();
|
||||
Logger.InfoPrint("It is " + ServerTime.Minutes / 60 + ":" + ServerTime.Minutes % 60 + " on Day " + ServerTime.Days + " in Year " + ServerTime.Years + "!!!");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue