Remove " " space from the names

This commit is contained in:
AtelierWindows 2021-01-28 20:56:27 +13:00
commit 8e451633dc
59 changed files with 391 additions and 391 deletions
Horse Isle Server/HorseIsleServer/Game/Horse

View file

@ -0,0 +1,547 @@
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game.Horse
{
class HorseInfo
{
public enum StatType
{
AGILITY,
CONFORMATION,
ENDURANCE,
PERSONALITY,
SPEED,
STRENGTH,
INTELIGENCE
}
public class StatCalculator
{
public StatCalculator(HorseInstance horse, StatType type)
{
baseHorse = horse;
horseStat = type;
}
private StatType horseStat;
private HorseInstance baseHorse;
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 CompanionOffset
{
get
{
int offsetBy = 0;
if (baseHorse.Equipment.Companion != null)
offsetBy += getOffetFrom(baseHorse.Equipment.Companion);
return offsetBy;
}
}
public int TackOffset
{
get
{
int offsetBy = 0;
if (baseHorse.Equipment.Saddle != null)
offsetBy += getOffetFrom(baseHorse.Equipment.Saddle);
if (baseHorse.Equipment.SaddlePad != null)
offsetBy += getOffetFrom(baseHorse.Equipment.SaddlePad);
if (baseHorse.Equipment.Bridle != null)
offsetBy += getOffetFrom(baseHorse.Equipment.Bridle);
return offsetBy;
}
}
public int Total
{
get
{
return BreedValue + CompanionOffset + TackOffset;
}
}
private int getOffetFrom(Item.ItemInformation tackPeice)
{
int offsetBy = 0;
foreach (Item.Effects effect in baseHorse.Equipment.Bridle.Effects)
{
string effects = effect.EffectsWhat;
switch (effects)
{
case "AGILITYOFFSET":
if (horseStat == StatType.AGILITY)
offsetBy += effect.EffectAmount;
break;
case "CONFORMATIONOFFSET":
if (horseStat == StatType.CONFORMATION)
offsetBy += effect.EffectAmount;
break;
case "ENDURANCEOFFSET":
if (horseStat == StatType.ENDURANCE)
offsetBy += effect.EffectAmount;
break;
case "PERSONALITYOFFSET":
if (horseStat == StatType.PERSONALITY)
offsetBy += effect.EffectAmount;
break;
case "SPEEDOFFSET":
if (horseStat == StatType.SPEED)
offsetBy += effect.EffectAmount;
break;
case "STRENGTHOFFSET":
if (horseStat == StatType.STRENGTH)
offsetBy += effect.EffectAmount;
break;
case "INTELLIGENCEOFFSET":
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 - baseHorse.Breed.BaseStats.Speed * 2);
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;
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;
}
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
{
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 struct 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 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 Meta;
}
public static string[] HorseNames;
public static List<Category> HorseCategories = new List<Category>();
public static List<Breed> Breeds = new List<Breed>();
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)
{
return ((double)height / 4.0);
}
public static string BreedViewerSwf(HorseInstance horse, string terrainTileType)
{
double hands = CalculateHands(horse.AdvancedStats.Height);
string swf = "breedviewer.swf?terrain=" + terrainTileType + "&breed=" + horse.Breed.Swf + "&color=" + horse.Color + "&hands=" + hands.ToString();
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);
}
}
}

View file

@ -0,0 +1,188 @@

using HISP.Security;
using HISP.Server;
namespace HISP.Game.Horse
{
class HorseInstance
{
public HorseInstance(HorseInfo.Breed breed, int randomId = -1, string loadName=null, string loadDescription = "", int loadSpoiled=0, string loadCategory="KEEPER", int loadMagicUsed=0, int loadAutoSell=0)
{
RandomId = RandomID.NextRandomId(randomId);
Owner = 0;
if(loadName == null)
{
if (breed.Type == "camel")
{
name = "Wild Camel";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "cow";
}
else
{
Sex = "bull";
}
}
else if (breed.Type == "llama")
{
name = "Jungle Llama";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "male";
}
else
{
Sex = "female";
}
}
else if (breed.Type == "zebra")
{
name = "Wild Zebra";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "stallion";
}
else
{
Sex = "mare";
}
}
else
{
name = "Wild Horse";
if (GameServer.RandomNumberGenerator.Next(0, 100) >= 50)
{
Sex = "stallion";
}
else
{
Sex = "mare";
}
}
}
else
{
name = loadName;
}
description = loadDescription;
Breed = breed;
Color = breed.Colors[GameServer.RandomNumberGenerator.Next(0, breed.Colors.Length)];
BasicStats = new HorseInfo.BasicStats(this, 1000, 0, 1000, 1000, 500, 1000, 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);
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;
TrainTimer = 0;
RanchId = 0;
Leaser = 0;
}
public int RanchId;
public int Leaser;
public int RandomId;
public int Owner;
public string Name
{
get
{
return name;
}
set
{
name = value;
Database.SetHorseName(this.RandomId, name);
}
}
public string Description
{
get
{
return description;
}
set
{
description = value;
Database.SetHorseDescription(this.RandomId, value);
}
}
public string Sex;
public string Color;
public int TrainTimer;
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 name;
private string description;
private int spoiled;
private int magicUsed;
private int autosell;
private string category;
public void ChangeNameWithoutUpdatingDatabase(string newName)
{
name = newName;
}
}
}

View file

@ -0,0 +1,295 @@
using HISP.Player;
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Horse
{
class WildHorse
{
public WildHorse(HorseInstance horse, int MapX = -1, int MapY = -1, int despawnTimeout=60, bool addToDatabase = true)
{
Instance = horse;
timeout = despawnTimeout;
if(MapX == -1 && MapY == -1)
{
while (true)
{
if (horse.Breed.SpawnInArea == null)
{
// Pick a random isle.
int isleId = GameServer.RandomNumberGenerator.Next(0, World.Isles.Count);
World.Isle isle = World.Isles[isleId];
// Pick x/y in isle.
int tryX = GameServer.RandomNumberGenerator.Next(isle.StartX, isle.EndX);
int tryY = GameServer.RandomNumberGenerator.Next(isle.StartY, isle.EndY);
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
// Check Tile Type
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type;
if (TileType == horse.Breed.SpawnOn)
{
if (Map.CheckPassable(tryX, tryY)) // Can the player stand over here?
{
x = tryX;
y = tryY;
break;
}
}
}
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);
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
// Check Tile Type
int TileID = Map.GetTileId(tryX, tryY, false);
string TileType = Map.TerrainTiles[TileID - 1].Type;
if (TileType == horse.Breed.SpawnOn)
{
if (Map.CheckPassable(tryX, tryY)) // Can the player stand over here?
{
x = tryX;
y = tryY;
break;
}
}
}
}
}
else
{
x = MapX;
y = MapY;
}
wildHorses.Add(this);
if(addToDatabase)
Database.AddWildHorse(this);
}
public void RandomWander()
{
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;
}
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
return;
if (World.InSpecialTile(tryX, tryY))
return;
if (Map.CheckPassable(tryX, tryY))
{
X = tryX;
Y = tryY;
return;
}
}
public void Escape()
{
while(true)
{
int tryX = X + GameServer.RandomNumberGenerator.Next(-15, 15);
int tryY = Y + GameServer.RandomNumberGenerator.Next(-15, 15);
// Horses cannot be in towns.
if (World.InTown(tryX, tryY))
continue;
if (World.InSpecialTile(tryX, tryY))
continue;
if (Map.CheckPassable(tryX, tryY))
{
X = tryX;
Y = tryY;
break;
}
}
}
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.Count)];
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()
{
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(wildHorse.Timeout % 5 == 0)
if (GameServer.RandomNumberGenerator.Next(0, 100) > 50)
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;
}
}