mirror of
https://github.com/islehorse/HISP.git
synced 2025-06-01 19:38:59 +12:00
Add Feature pt1
This commit is contained in:
parent
a184e4d735
commit
092534e331
131 changed files with 3113 additions and 1418 deletions
HorseIsleServer/LibHISP/Game/Horse
659
HorseIsleServer/LibHISP/Game/Horse/HorseInfo.cs
Normal file
659
HorseIsleServer/LibHISP/Game/Horse/HorseInfo.cs
Normal file
|
@ -0,0 +1,659 @@
|
|||
using HISP.Server;
|
||||
using HISP.Game.Items;
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using HISP.Player;
|
||||
|
||||
namespace HISP.Game.Horse
|
||||
{
|
||||
public class HorseInfo
|
||||
{
|
||||
public enum StatType
|
||||
{
|
||||
AGILITY,
|
||||
CONFORMATION,
|
||||
ENDURANCE,
|
||||
PERSONALITY,
|
||||
SPEED,
|
||||
STRENGTH,
|
||||
INTELIGENCE
|
||||
}
|
||||
public class StatCalculator
|
||||
{
|
||||
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
|
||||
{
|
||||
switch (horseStat)
|
||||
{
|
||||
case StatType.AGILITY:
|
||||
return baseHorse.Breed.BaseStats.Agility;
|
||||
case StatType.CONFORMATION:
|
||||
return baseHorse.Breed.BaseStats.Conformation;
|
||||
case StatType.ENDURANCE:
|
||||
return baseHorse.Breed.BaseStats.Endurance;
|
||||
case StatType.PERSONALITY:
|
||||
return baseHorse.Breed.BaseStats.Personality;
|
||||
case StatType.SPEED:
|
||||
return baseHorse.Breed.BaseStats.Speed;
|
||||
case StatType.STRENGTH:
|
||||
return baseHorse.Breed.BaseStats.Strength;
|
||||
case StatType.INTELIGENCE:
|
||||
return baseHorse.Breed.BaseStats.Inteligence;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
public int MaxValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return BaseValue * 2;
|
||||
}
|
||||
}
|
||||
public int BreedValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return BaseValue + BreedOffset;
|
||||
}
|
||||
}
|
||||
public int BreedOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (horseStat)
|
||||
{
|
||||
case StatType.AGILITY:
|
||||
return baseHorse.AdvancedStats.Agility;
|
||||
case StatType.CONFORMATION:
|
||||
return baseHorse.AdvancedStats.Conformation;
|
||||
case StatType.ENDURANCE:
|
||||
return baseHorse.AdvancedStats.Endurance;
|
||||
case StatType.PERSONALITY:
|
||||
return baseHorse.AdvancedStats.Personality;
|
||||
case StatType.SPEED:
|
||||
return baseHorse.AdvancedStats.Speed;
|
||||
case StatType.STRENGTH:
|
||||
return baseHorse.AdvancedStats.Strength;
|
||||
case StatType.INTELIGENCE:
|
||||
return baseHorse.AdvancedStats.Inteligence;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
switch (horseStat)
|
||||
{
|
||||
case StatType.AGILITY:
|
||||
baseHorse.AdvancedStats.Agility = value;
|
||||
break;
|
||||
case StatType.CONFORMATION:
|
||||
baseHorse.AdvancedStats.Conformation = value;
|
||||
break;
|
||||
case StatType.ENDURANCE:
|
||||
baseHorse.AdvancedStats.Endurance = value;
|
||||
break;
|
||||
case StatType.PERSONALITY:
|
||||
baseHorse.AdvancedStats.Personality = value;
|
||||
break;
|
||||
case StatType.SPEED:
|
||||
baseHorse.AdvancedStats.Speed = value;
|
||||
break;
|
||||
case StatType.STRENGTH:
|
||||
baseHorse.AdvancedStats.Strength = value;
|
||||
break;
|
||||
case StatType.INTELIGENCE:
|
||||
baseHorse.AdvancedStats.Inteligence = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
{
|
||||
if(baseHorse.Equipment.Companion != null)
|
||||
return baseHorse.Equipment.Companion.GetMiscFlag(0);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int TackOffset
|
||||
{
|
||||
get
|
||||
{
|
||||
int offsetBy = 0;
|
||||
if (baseHorse.Equipment.Saddle != null)
|
||||
offsetBy += getOffsetFrom(baseHorse.Equipment.Saddle);
|
||||
if (baseHorse.Equipment.SaddlePad != null)
|
||||
offsetBy += getOffsetFrom(baseHorse.Equipment.SaddlePad);
|
||||
if (baseHorse.Equipment.Bridle != null)
|
||||
offsetBy += getOffsetFrom(baseHorse.Equipment.Bridle);
|
||||
return offsetBy;
|
||||
}
|
||||
}
|
||||
public int Total
|
||||
{
|
||||
get
|
||||
{
|
||||
return BreedValue + CompanionOffset + TackOffset + CompetitionGearOffset;
|
||||
}
|
||||
}
|
||||
|
||||
private int getOffsetFrom(Item.ItemInformation tackPeice)
|
||||
{
|
||||
int offsetBy = 0;
|
||||
foreach (Item.Effects effect in tackPeice.Effects)
|
||||
{
|
||||
string effects = effect.EffectsWhat;
|
||||
switch (effects)
|
||||
{
|
||||
case "AGILITY":
|
||||
if (horseStat == StatType.AGILITY)
|
||||
offsetBy += effect.EffectAmount;
|
||||
break;
|
||||
case "CONFORMATION":
|
||||
if (horseStat == StatType.CONFORMATION)
|
||||
offsetBy += effect.EffectAmount;
|
||||
break;
|
||||
case "ENDURANCE":
|
||||
if (horseStat == StatType.ENDURANCE)
|
||||
offsetBy += effect.EffectAmount;
|
||||
break;
|
||||
case "PERSONALITY":
|
||||
if (horseStat == StatType.PERSONALITY)
|
||||
offsetBy += effect.EffectAmount;
|
||||
break;
|
||||
case "SPEED":
|
||||
if (horseStat == StatType.SPEED)
|
||||
offsetBy += effect.EffectAmount;
|
||||
break;
|
||||
case "STRENGTH":
|
||||
if (horseStat == StatType.STRENGTH)
|
||||
offsetBy += effect.EffectAmount;
|
||||
break;
|
||||
case "INTELLIGENCE":
|
||||
if (horseStat == StatType.INTELIGENCE)
|
||||
offsetBy += effect.EffectAmount;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
return offsetBy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class AdvancedStats
|
||||
{
|
||||
public AdvancedStats(HorseInstance horse, int newSpeed,int newStrength, int newConformation, int newAgility, int newInteligence, int newEndurance, int newPersonality, int newHeight)
|
||||
{
|
||||
if(horse != null)
|
||||
baseHorse = horse;
|
||||
speed = newSpeed;
|
||||
strength = newStrength;
|
||||
conformation = newConformation;
|
||||
agility = newAgility;
|
||||
endurance = newEndurance;
|
||||
inteligence = newInteligence;
|
||||
personality = newPersonality;
|
||||
height = newHeight;
|
||||
}
|
||||
|
||||
|
||||
public int Speed
|
||||
{
|
||||
get
|
||||
{
|
||||
return speed;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > ((baseHorse.Breed.BaseStats.Speed * 2) - baseHorse.Breed.BaseStats.Speed))
|
||||
value = ((baseHorse.Breed.BaseStats.Speed * 2) - baseHorse.Breed.BaseStats.Speed);
|
||||
Database.SetHorseSpeed(baseHorse.RandomId, value);
|
||||
speed = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Strength
|
||||
{
|
||||
get
|
||||
{
|
||||
return strength;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > ((baseHorse.Breed.BaseStats.Strength * 2) - baseHorse.Breed.BaseStats.Strength))
|
||||
value = ((baseHorse.Breed.BaseStats.Strength * 2) - baseHorse.Breed.BaseStats.Strength);
|
||||
Database.SetHorseStrength(baseHorse.RandomId, value);
|
||||
strength = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Conformation
|
||||
{
|
||||
get
|
||||
{
|
||||
return conformation;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > ((baseHorse.Breed.BaseStats.Conformation * 2) - baseHorse.Breed.BaseStats.Conformation))
|
||||
value = ((baseHorse.Breed.BaseStats.Conformation * 2) - baseHorse.Breed.BaseStats.Conformation);
|
||||
Database.SetHorseConformation(baseHorse.RandomId, value);
|
||||
conformation = value;
|
||||
}
|
||||
}
|
||||
public int Agility
|
||||
{
|
||||
get
|
||||
{
|
||||
return agility;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > ((baseHorse.Breed.BaseStats.Agility * 2) - baseHorse.Breed.BaseStats.Agility))
|
||||
value = ((baseHorse.Breed.BaseStats.Agility * 2) - baseHorse.Breed.BaseStats.Agility);
|
||||
Database.SetHorseAgility(baseHorse.RandomId, value);
|
||||
agility = value;
|
||||
}
|
||||
}
|
||||
public int Endurance
|
||||
{
|
||||
get
|
||||
{
|
||||
return endurance;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > ((baseHorse.Breed.BaseStats.Endurance * 2) - baseHorse.Breed.BaseStats.Endurance))
|
||||
value = ((baseHorse.Breed.BaseStats.Endurance * 2) - baseHorse.Breed.BaseStats.Endurance);
|
||||
Database.SetHorseEndurance(baseHorse.RandomId, value);
|
||||
endurance = value;
|
||||
}
|
||||
}
|
||||
public int Inteligence
|
||||
{
|
||||
get
|
||||
{
|
||||
return inteligence;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > ((baseHorse.Breed.BaseStats.Inteligence* 2) - baseHorse.Breed.BaseStats.Inteligence))
|
||||
value = ((baseHorse.Breed.BaseStats.Inteligence * 2) - baseHorse.Breed.BaseStats.Inteligence);
|
||||
Database.SetHorseInteligence(baseHorse.RandomId, value);
|
||||
inteligence = value;
|
||||
}
|
||||
}
|
||||
public int Personality
|
||||
{
|
||||
get
|
||||
{
|
||||
return personality;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > ((baseHorse.Breed.BaseStats.Personality * 2) - baseHorse.Breed.BaseStats.Personality))
|
||||
value = ((baseHorse.Breed.BaseStats.Personality * 2) - baseHorse.Breed.BaseStats.Personality);
|
||||
Database.SetHorsePersonality(baseHorse.RandomId, value);
|
||||
personality = value;
|
||||
}
|
||||
}
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return height;
|
||||
}
|
||||
set
|
||||
{
|
||||
height = value;
|
||||
Database.SetHorseHeight(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
public int MinHeight;
|
||||
public int MaxHeight;
|
||||
|
||||
private HorseInstance baseHorse;
|
||||
private int speed;
|
||||
private int strength;
|
||||
private int conformation;
|
||||
private int agility;
|
||||
private int endurance;
|
||||
private int inteligence;
|
||||
private int personality;
|
||||
private int height;
|
||||
}
|
||||
public class BasicStats
|
||||
{
|
||||
public BasicStats(HorseInstance horse, int newHealth, int newShoes, int newHunger, int newThirst, int newMood, int newGroom, int newTiredness, int newExperience)
|
||||
{
|
||||
baseHorse = horse;
|
||||
health = newHealth;
|
||||
shoes = newShoes;
|
||||
hunger = newHunger;
|
||||
thirst = newThirst;
|
||||
mood = newMood;
|
||||
groom = newGroom;
|
||||
tiredness = newTiredness;
|
||||
experience = newExperience;
|
||||
|
||||
}
|
||||
public int Health
|
||||
{
|
||||
get
|
||||
{
|
||||
return health;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 1000)
|
||||
value = 1000;
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
health = value;
|
||||
Database.SetHorseHealth(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
public int Shoes
|
||||
{
|
||||
get
|
||||
{
|
||||
return shoes;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 1000)
|
||||
value = 1000;
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
shoes = value;
|
||||
Database.SetHorseShoes(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
public int Hunger {
|
||||
get
|
||||
{
|
||||
return hunger;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 1000)
|
||||
value = 1000;
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
hunger = value;
|
||||
Database.SetHorseHunger(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
public int Thirst
|
||||
{
|
||||
get
|
||||
{
|
||||
return thirst;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 1000)
|
||||
value = 1000;
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
thirst = value;
|
||||
Database.SetHorseThirst(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
public int Mood
|
||||
{
|
||||
get
|
||||
{
|
||||
return mood;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
public int Groom
|
||||
{
|
||||
get
|
||||
{
|
||||
return groom;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 1000)
|
||||
value = 1000;
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
groom = value;
|
||||
Database.SetHorseGroom(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
public int Tiredness
|
||||
{
|
||||
get
|
||||
{
|
||||
return tiredness;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 1000)
|
||||
value = 1000;
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
tiredness = value;
|
||||
Database.SetHorseTiredness(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
public int Experience
|
||||
{
|
||||
get
|
||||
{
|
||||
return experience;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
value = 0;
|
||||
experience = value;
|
||||
Database.SetHorseExperience(baseHorse.RandomId, value);
|
||||
}
|
||||
}
|
||||
|
||||
private HorseInstance baseHorse;
|
||||
private int health;
|
||||
private int shoes;
|
||||
private int hunger;
|
||||
private int thirst;
|
||||
private int mood;
|
||||
private int groom;
|
||||
private int tiredness;
|
||||
private int experience;
|
||||
}
|
||||
|
||||
public class Breed
|
||||
{
|
||||
public int Id;
|
||||
public string Name;
|
||||
public string Description;
|
||||
public AdvancedStats BaseStats;
|
||||
public string[] Colors;
|
||||
public string SpawnOn;
|
||||
public string SpawnInArea;
|
||||
public string Swf;
|
||||
public string Type;
|
||||
|
||||
public string[] GenderTypes()
|
||||
{
|
||||
string[] options = new string[2];
|
||||
if (Type == "camel")
|
||||
{
|
||||
options[0] = "cow";
|
||||
options[1] = "bull";
|
||||
}
|
||||
else if (Type == "llama")
|
||||
{
|
||||
options[0] = "male";
|
||||
options[1] = "female";
|
||||
}
|
||||
else
|
||||
{
|
||||
options[0] = "stallion";
|
||||
options[1] = "mare";
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
||||
public struct HorseEquips
|
||||
{
|
||||
public Item.ItemInformation Saddle;
|
||||
public Item.ItemInformation SaddlePad;
|
||||
public Item.ItemInformation Bridle;
|
||||
public Item.ItemInformation Companion;
|
||||
}
|
||||
|
||||
public struct Category
|
||||
{
|
||||
public string Name;
|
||||
public string MetaOthers;
|
||||
public string Meta;
|
||||
}
|
||||
|
||||
public static string[] HorseNames;
|
||||
private static List<Category> horseCategories = new List<Category>();
|
||||
private static List<Breed> breeds = new List<Breed>();
|
||||
|
||||
public static void AddBreed(Breed breed)
|
||||
{
|
||||
breeds.Add(breed);
|
||||
}
|
||||
|
||||
public static void AddHorseCategory(Category category)
|
||||
{
|
||||
horseCategories.Add(category);
|
||||
}
|
||||
public static Category[] HorseCategories
|
||||
{
|
||||
get
|
||||
{
|
||||
return horseCategories.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static Breed[] Breeds
|
||||
{
|
||||
get
|
||||
{
|
||||
return breeds.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GenerateHorseName()
|
||||
{
|
||||
int indx = 0;
|
||||
int max = HorseNames.Length;
|
||||
int i = GameServer.RandomNumberGenerator.Next(indx, max);
|
||||
return HorseNames[i];
|
||||
}
|
||||
public static double CalculateHands(int height, bool isBreedViewer)
|
||||
{
|
||||
if(isBreedViewer)
|
||||
return ((double)height / 4.00);
|
||||
else
|
||||
{
|
||||
int h1 = 0;
|
||||
int h2 = 0;
|
||||
for(int i = 0; i < height; i++)
|
||||
{
|
||||
h2++;
|
||||
if (h2 == 4)
|
||||
{
|
||||
h2 = 0;
|
||||
h1++;
|
||||
}
|
||||
}
|
||||
double hands = double.Parse(h1 + "." + h2, CultureInfo.InvariantCulture); // This is terrible. dont do this.
|
||||
return hands;
|
||||
}
|
||||
}
|
||||
public static string BreedViewerSwf(HorseInstance horse, string terrainTileType)
|
||||
{
|
||||
double hands = CalculateHands(horse.AdvancedStats.Height, true);
|
||||
|
||||
string swf = "breedviewer.swf?terrain=" + terrainTileType + "&breed=" + horse.Breed.Swf + "&color=" + horse.Color + "&hands=" + hands.ToString(CultureInfo.InvariantCulture);
|
||||
if (horse.Equipment.Saddle != null)
|
||||
swf += "&saddle=" + horse.Equipment.Saddle.EmbedSwf;
|
||||
if (horse.Equipment.SaddlePad != null)
|
||||
swf += "&saddlepad=" + horse.Equipment.SaddlePad.EmbedSwf;
|
||||
if (horse.Equipment.Bridle != null)
|
||||
swf += "&bridle=" + horse.Equipment.Bridle.EmbedSwf;
|
||||
if (horse.Equipment.Companion != null)
|
||||
swf += "&companion=" + horse.Equipment.Companion.EmbedSwf;
|
||||
swf += "&junk=";
|
||||
|
||||
return swf;
|
||||
}
|
||||
public static Breed GetBreedById(int id)
|
||||
{
|
||||
foreach(Breed breed in Breeds)
|
||||
{
|
||||
if (breed.Id == id)
|
||||
return breed;
|
||||
}
|
||||
throw new KeyNotFoundException("No horse breed with id " + id);
|
||||
}
|
||||
}
|
||||
}
|
229
HorseIsleServer/LibHISP/Game/Horse/HorseInstance.cs
Normal file
229
HorseIsleServer/LibHISP/Game/Horse/HorseInstance.cs
Normal file
|
@ -0,0 +1,229 @@
|
|||
|
||||
using HISP.Security;
|
||||
using HISP.Server;
|
||||
|
||||
namespace HISP.Game.Horse
|
||||
{
|
||||
public class HorseInstance
|
||||
{
|
||||
public HorseInstance(HorseInfo.Breed breed, int randomId = -1, string loadColor = null ,string loadName=null, string loadDescription = "", int loadSpoiled=0, string loadCategory="KEEPER", int loadMagicUsed=0, int loadAutoSell=0, int leaseTimer=0, bool loadHidden=false, int loadOwner=0)
|
||||
{
|
||||
RandomId = RandomID.NextRandomId(randomId);
|
||||
owner = loadOwner;
|
||||
if(loadName == null)
|
||||
{
|
||||
|
||||
if (breed.Type == "camel")
|
||||
{
|
||||
name = "Wild Camel";
|
||||
|
||||
}
|
||||
else if (breed.Type == "llama")
|
||||
{
|
||||
name = "Jungle Llama";
|
||||
}
|
||||
else if (breed.Type == "zebra")
|
||||
{
|
||||
name = "Wild Zebra";
|
||||
}
|
||||
else
|
||||
{
|
||||
name = "Wild Horse";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
name = loadName;
|
||||
}
|
||||
if(GameServer.RandomNumberGenerator.Next(0, 100) > 50)
|
||||
Gender = breed.GenderTypes()[1];
|
||||
else
|
||||
Gender = breed.GenderTypes()[0];
|
||||
|
||||
description = loadDescription;
|
||||
Breed = breed;
|
||||
|
||||
|
||||
BasicStats = new HorseInfo.BasicStats(this, 1000, 0, 1000, 1000, 500, 200, 1000, 0);
|
||||
|
||||
int inteligence = (GameServer.RandomNumberGenerator.Next(breed.BaseStats.Inteligence, (breed.BaseStats.Inteligence * 2)) - breed.BaseStats.Inteligence);
|
||||
int personality = (GameServer.RandomNumberGenerator.Next(breed.BaseStats.Personality, (breed.BaseStats.Personality * 2)) - breed.BaseStats.Personality);
|
||||
int height = GameServer.RandomNumberGenerator.Next(breed.BaseStats.MinHeight, breed.BaseStats.MaxHeight + 1);
|
||||
AdvancedStats = new HorseInfo.AdvancedStats(this, 0, 0, 0, 0, inteligence, 0, personality, height);
|
||||
|
||||
Equipment = new HorseInfo.HorseEquips();
|
||||
autosell = loadAutoSell;
|
||||
category = loadCategory;
|
||||
spoiled = loadSpoiled;
|
||||
magicUsed = loadMagicUsed;
|
||||
leaseTime = leaseTimer;
|
||||
hidden = loadHidden;
|
||||
if(loadColor != null)
|
||||
color = loadColor;
|
||||
else
|
||||
color = breed.Colors[GameServer.RandomNumberGenerator.Next(0, breed.Colors.Length)];
|
||||
Leaser = 0;
|
||||
}
|
||||
public int Leaser;
|
||||
public int RandomId;
|
||||
public int Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
set
|
||||
{
|
||||
owner = value;
|
||||
Database.SetHorseOwner(RandomId, owner);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Hidden
|
||||
{
|
||||
get
|
||||
{
|
||||
return hidden;
|
||||
}
|
||||
set
|
||||
{
|
||||
hidden = value;
|
||||
Database.SetHorseHidden(RandomId, value);
|
||||
}
|
||||
}
|
||||
public int LeaseTime
|
||||
{
|
||||
get
|
||||
{
|
||||
return leaseTime;
|
||||
}
|
||||
set
|
||||
{
|
||||
leaseTime = value;
|
||||
Database.SetLeaseTime(this.RandomId, leaseTime);
|
||||
}
|
||||
}
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return name;
|
||||
}
|
||||
set
|
||||
{
|
||||
name = value.Trim();
|
||||
Database.SetHorseName(this.RandomId, name);
|
||||
}
|
||||
}
|
||||
public string Description
|
||||
{
|
||||
get
|
||||
{
|
||||
return description;
|
||||
}
|
||||
set
|
||||
{
|
||||
description = value.Trim();
|
||||
Database.SetHorseDescription(this.RandomId, description);
|
||||
}
|
||||
}
|
||||
public string Gender;
|
||||
public string Color
|
||||
{
|
||||
get
|
||||
{
|
||||
return color;
|
||||
}
|
||||
set
|
||||
{
|
||||
color = value;
|
||||
Database.SetHorseColor(this.RandomId, color);
|
||||
}
|
||||
}
|
||||
public int TrainTimer
|
||||
{
|
||||
get
|
||||
{
|
||||
int timeout = Database.GetHorseTrainTimeout(this.RandomId);
|
||||
if (timeout < 0)
|
||||
return 0;
|
||||
else
|
||||
return timeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetHorseTrainTimeout(this.RandomId, value);
|
||||
}
|
||||
}
|
||||
public HorseInfo.Breed Breed;
|
||||
public HorseInfo.BasicStats BasicStats;
|
||||
public HorseInfo.AdvancedStats AdvancedStats;
|
||||
public HorseInfo.HorseEquips Equipment;
|
||||
public int AutoSell
|
||||
{
|
||||
get
|
||||
{
|
||||
return autosell;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetHorseAutoSell(RandomId, value);
|
||||
autosell = value;
|
||||
}
|
||||
}
|
||||
public int Spoiled
|
||||
{
|
||||
get
|
||||
{
|
||||
return spoiled;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetHorseSpoiled(RandomId, value);
|
||||
spoiled = value;
|
||||
}
|
||||
}
|
||||
public int MagicUsed
|
||||
{
|
||||
get
|
||||
{
|
||||
return magicUsed;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetHorseMagicUsed(RandomId, value);
|
||||
magicUsed = value;
|
||||
}
|
||||
}
|
||||
public string Category
|
||||
{
|
||||
get
|
||||
{
|
||||
return category;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetHorseCategory(RandomId, value);
|
||||
category = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string color;
|
||||
private int owner;
|
||||
private string name;
|
||||
private string description;
|
||||
private int spoiled;
|
||||
private int leaseTime;
|
||||
private bool hidden;
|
||||
private int magicUsed;
|
||||
private int autosell;
|
||||
private string category;
|
||||
|
||||
public void ChangeNameWithoutUpdatingDatabase(string newName)
|
||||
{
|
||||
name = newName;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
129
HorseIsleServer/LibHISP/Game/Horse/Leaser.cs
Normal file
129
HorseIsleServer/LibHISP/Game/Horse/Leaser.cs
Normal file
|
@ -0,0 +1,129 @@
|
|||
using HISP.Game.Items;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace HISP.Game.Horse
|
||||
{
|
||||
public class Leaser
|
||||
{
|
||||
private static List<Leaser> horseLeasers = new List<Leaser>();
|
||||
public static void AddHorseLeaser(Leaser leaser)
|
||||
{
|
||||
horseLeasers.Add(leaser);
|
||||
}
|
||||
|
||||
public static Leaser[] HorseLeasers
|
||||
{
|
||||
get
|
||||
{
|
||||
return horseLeasers.ToArray();
|
||||
}
|
||||
}
|
||||
public Leaser(int breedId, int saddle, int saddlePad, int bridle)
|
||||
{
|
||||
Breed = HorseInfo.GetBreedById(breedId);
|
||||
|
||||
if (saddle != -1)
|
||||
Saddle = Item.GetItemById(saddle);
|
||||
if (saddlePad != -1)
|
||||
SaddlePad = Item.GetItemById(saddlePad);
|
||||
if (bridle != -1)
|
||||
Bridle = Item.GetItemById(bridle);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public int LeaseId;
|
||||
public string ButtonId;
|
||||
public string Info;
|
||||
public string OnLeaseText;
|
||||
public int Price;
|
||||
public int Minutes;
|
||||
|
||||
// Horse
|
||||
|
||||
public HorseInfo.Breed Breed;
|
||||
public string HorseName;
|
||||
public string Color;
|
||||
public string Gender;
|
||||
|
||||
public int Health;
|
||||
public int Shoes;
|
||||
public int Hunger;
|
||||
public int Thirst;
|
||||
public int Mood;
|
||||
public int Groom;
|
||||
public int Tiredness;
|
||||
public int Experience;
|
||||
|
||||
public Item.ItemInformation Saddle = null;
|
||||
public Item.ItemInformation SaddlePad = null;
|
||||
public Item.ItemInformation Bridle = null;
|
||||
|
||||
public int Speed;
|
||||
public int Strength;
|
||||
public int Conformation;
|
||||
public int Agility;
|
||||
public int Inteligence;
|
||||
public int Endurance;
|
||||
public int Personality;
|
||||
public int Height;
|
||||
|
||||
public HorseInstance GenerateLeaseHorse()
|
||||
{
|
||||
HorseInstance instance = new HorseInstance(this.Breed, loadColor: this.Color, loadCategory: "LEASED", leaseTimer: this.Minutes);
|
||||
instance.Name = this.HorseName;
|
||||
instance.Gender = this.Gender;
|
||||
instance.Leaser = this.LeaseId;
|
||||
|
||||
instance.BasicStats = new HorseInfo.BasicStats(instance, Health, Shoes, Hunger, Thirst, Mood, Groom, Tiredness, Experience);
|
||||
instance.AdvancedStats = new HorseInfo.AdvancedStats(instance, Speed, Strength, Conformation, Agility, Inteligence, Endurance, Personality, Height);
|
||||
|
||||
instance.Equipment.Saddle = this.Saddle;
|
||||
instance.Equipment.SaddlePad = this.SaddlePad;
|
||||
instance.Equipment.Bridle = this.Bridle;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static bool LeaserButtonIdExists(string bid)
|
||||
{
|
||||
foreach (Leaser leaser in HorseLeasers)
|
||||
{
|
||||
if (leaser.ButtonId == bid)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Leaser GetLeaserByButtonId(string bid)
|
||||
{
|
||||
foreach(Leaser leaser in HorseLeasers)
|
||||
{
|
||||
if(leaser.ButtonId == bid)
|
||||
{
|
||||
return leaser;
|
||||
}
|
||||
}
|
||||
throw new KeyNotFoundException("No leaser with button id: " + bid + " found.");
|
||||
}
|
||||
|
||||
public static Leaser[] GetLeasersById(int id)
|
||||
{
|
||||
List<Leaser> leasers = new List<Leaser>();
|
||||
|
||||
foreach (Leaser leaser in HorseLeasers)
|
||||
{
|
||||
if (leaser.LeaseId == id)
|
||||
{
|
||||
leasers.Add(leaser);
|
||||
}
|
||||
}
|
||||
return leasers.ToArray();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
318
HorseIsleServer/LibHISP/Game/Horse/WildHorse.cs
Normal file
318
HorseIsleServer/LibHISP/Game/Horse/WildHorse.cs
Normal file
|
@ -0,0 +1,318 @@
|
|||
using HISP.Player;
|
||||
using HISP.Server;
|
||||
using System.Collections.Generic;
|
||||
namespace HISP.Game.Horse
|
||||
{
|
||||
|
||||
public class WildHorse
|
||||
{
|
||||
|
||||
public bool CanHorseBeHere(int x, int y, bool checkSpawnLocationValid=true)
|
||||
{
|
||||
|
||||
// Horses cannot be in towns.
|
||||
if (World.InTown(x, y))
|
||||
return false;
|
||||
if (World.InSpecialTile(x, y))
|
||||
return false;
|
||||
if (!World.InIsle(x, y))
|
||||
return false;
|
||||
|
||||
// Check area
|
||||
if(checkSpawnLocationValid)
|
||||
{
|
||||
if (this.Instance.Breed.SpawnInArea != null)
|
||||
{
|
||||
if (World.InArea(x, y))
|
||||
{
|
||||
if (World.GetArea(x, y).Name != this.Instance.Breed.SpawnInArea)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Check Tile Type
|
||||
int TileID = Map.GetTileId(x, y, false);
|
||||
string TileType = Map.TerrainTiles[TileID - 1].Type;
|
||||
if(checkSpawnLocationValid)
|
||||
{
|
||||
if (TileType != this.Instance.Breed.SpawnOn)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (Map.CheckPassable(x, y)) // Can the player stand over here?
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
public WildHorse(HorseInstance horse, int MapX = -1, int MapY = -1, int despawnTimeout=1440, bool addToDatabase = true)
|
||||
{
|
||||
Instance = horse;
|
||||
timeout = despawnTimeout;
|
||||
if(MapX == -1 && MapY == -1)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
if (horse.Breed.SpawnInArea == null)
|
||||
{
|
||||
|
||||
|
||||
// Pick x/y
|
||||
int tryX = GameServer.RandomNumberGenerator.Next(0, Map.Width);
|
||||
int tryY = GameServer.RandomNumberGenerator.Next(0, Map.Height);
|
||||
|
||||
if (CanHorseBeHere(tryX, tryY))
|
||||
{
|
||||
x = tryX;
|
||||
y = tryY;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
World.Zone zone = World.GetZoneByName(horse.Breed.SpawnInArea);
|
||||
// Pick x/y in zone.
|
||||
int tryX = GameServer.RandomNumberGenerator.Next(zone.StartX, zone.EndX);
|
||||
int tryY = GameServer.RandomNumberGenerator.Next(zone.StartY, zone.EndY);
|
||||
|
||||
if (CanHorseBeHere(tryX, tryY))
|
||||
{
|
||||
x = tryX;
|
||||
y = tryY;
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
x = MapX;
|
||||
y = MapY;
|
||||
}
|
||||
wildHorses.Add(this);
|
||||
if(addToDatabase)
|
||||
Database.AddWildHorse(this);
|
||||
}
|
||||
|
||||
|
||||
public void RandomWander()
|
||||
{
|
||||
if (GameServer.GetUsersAt(this.X, this.Y, true, true).Length > 0)
|
||||
return;
|
||||
|
||||
int tries = 0;
|
||||
while(true)
|
||||
{
|
||||
int direction = GameServer.RandomNumberGenerator.Next(0, 4);
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
bool check = CanHorseBeHere(this.X, this.Y); // if the horse is allready in an invalid position..
|
||||
|
||||
if (CanHorseBeHere(tryX, tryY, check))
|
||||
{
|
||||
X = tryX;
|
||||
Y = tryY;
|
||||
break;
|
||||
}
|
||||
|
||||
if(tries >= 100)
|
||||
{
|
||||
Logger.ErrorPrint("Wild Horse: " + Instance.Name + " " + Instance.Breed.Name + " is stuck (cant move after 100 tries) at " + x.ToString() + ", " + y.ToString());
|
||||
break;
|
||||
}
|
||||
tries++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Escape()
|
||||
{
|
||||
for(int i = 0; i < 100; i++)
|
||||
{
|
||||
int tryX = X + GameServer.RandomNumberGenerator.Next(-5, 5);
|
||||
int tryY = Y + GameServer.RandomNumberGenerator.Next(-5, 5);
|
||||
|
||||
bool check = CanHorseBeHere(this.X, this.Y); // if the horse is allready in an invalid position..
|
||||
|
||||
if (CanHorseBeHere(tryX, tryY, check))
|
||||
{
|
||||
X = tryX;
|
||||
Y = tryY;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.ErrorPrint("Horse is stuck (cannot move after 1000 tries) " + Instance.Breed.Name + " at X" + X + " Y" + Y);
|
||||
}
|
||||
|
||||
public void Capture(User forUser)
|
||||
{
|
||||
forUser.HorseInventory.AddHorse(this.Instance);
|
||||
Despawn(this);
|
||||
}
|
||||
|
||||
private static List<WildHorse> wildHorses = new List<WildHorse>();
|
||||
public static WildHorse[] WildHorses
|
||||
{
|
||||
get
|
||||
{
|
||||
return wildHorses.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static void GenerateHorses()
|
||||
{
|
||||
Logger.InfoPrint("Generating horses.");
|
||||
while(wildHorses.Count < 40)
|
||||
{
|
||||
HorseInfo.Breed horseBreed = HorseInfo.Breeds[GameServer.RandomNumberGenerator.Next(0, HorseInfo.Breeds.Length)];
|
||||
if (horseBreed.Swf == "")
|
||||
continue;
|
||||
if (horseBreed.SpawnInArea == "none") // no unipegs >_>
|
||||
continue;
|
||||
|
||||
HorseInstance horseInst = new HorseInstance(horseBreed);
|
||||
WildHorse wildHorse = new WildHorse(horseInst);
|
||||
|
||||
Logger.DebugPrint("Created " + horseBreed.Name + " at X:" + wildHorse.X + ", Y:" + wildHorse.Y);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
Database.LoadWildHorses();
|
||||
GenerateHorses();
|
||||
}
|
||||
|
||||
public static WildHorse[] GetHorsesAt(int x, int y)
|
||||
{
|
||||
List<WildHorse> horses = new List<WildHorse>();
|
||||
foreach (WildHorse wildHorse in WildHorses)
|
||||
{
|
||||
if (wildHorse.X == x && wildHorse.Y == y)
|
||||
horses.Add(wildHorse);
|
||||
}
|
||||
return horses.ToArray();
|
||||
}
|
||||
|
||||
public static bool DoesHorseExist(int randomId)
|
||||
{
|
||||
foreach (WildHorse wildHorse in WildHorses)
|
||||
{
|
||||
if (wildHorse.Instance.RandomId == randomId)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static WildHorse GetHorseById(int randomId)
|
||||
{
|
||||
foreach(WildHorse wildHorse in WildHorses)
|
||||
{
|
||||
if (wildHorse.Instance.RandomId == randomId)
|
||||
return wildHorse;
|
||||
}
|
||||
throw new KeyNotFoundException("No horse with id: " + randomId + " was found.");
|
||||
}
|
||||
|
||||
public static void Despawn(WildHorse horse)
|
||||
{
|
||||
Database.RemoveWildHorse(horse.Instance.RandomId);
|
||||
wildHorses.Remove(horse);
|
||||
}
|
||||
|
||||
public static void Update()
|
||||
{
|
||||
Logger.DebugPrint("Making horses wander.");
|
||||
foreach (WildHorse wildHorse in WildHorses)
|
||||
{
|
||||
wildHorse.Timeout -= 1;
|
||||
|
||||
if (GameServer.GetUsersAt(wildHorse.X, wildHorse.Y, true, true).Length > 0)
|
||||
continue;
|
||||
|
||||
if (wildHorse.Timeout <= 0)
|
||||
Despawn(wildHorse);
|
||||
|
||||
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 25)
|
||||
wildHorse.RandomWander();
|
||||
}
|
||||
if(WildHorses.Length < 40)
|
||||
{
|
||||
GenerateHorses();
|
||||
}
|
||||
}
|
||||
public HorseInstance Instance;
|
||||
public int X
|
||||
{
|
||||
get
|
||||
{
|
||||
return x;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetWildHorseX(this.Instance.RandomId, value);
|
||||
x = value;
|
||||
}
|
||||
}
|
||||
public int Y
|
||||
{
|
||||
get
|
||||
{
|
||||
return y;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetWildHorseY(this.Instance.RandomId, value);
|
||||
y = value;
|
||||
}
|
||||
}
|
||||
public int Timeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return timeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
Database.SetWildHorseTimeout(this.Instance.RandomId, value);
|
||||
timeout = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int x;
|
||||
private int y;
|
||||
private int timeout;
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue