Add Feature pt1

This commit is contained in:
Silica 2022-03-07 07:08:47 -05:00
parent a184e4d735
commit 092534e331
131 changed files with 3113 additions and 1418 deletions

View file

@ -0,0 +1,373 @@
using HISP.Game.Horse;
using HISP.Player;
using HISP.Security;
using HISP.Server;
using System.Collections.Generic;
namespace HISP.Game.Services
{
public class Auction
{
private static List<Auction> auctionRooms = new List<Auction>();
public static Auction[] AuctionRooms
{
get
{
return auctionRooms.ToArray();
}
}
public Auction(int id)
{
RoomId = id;
auctionEntries = new List<AuctionEntry>();
Database.LoadAuctionRoom(this, RoomId);
}
public class AuctionBid
{
public const int MAX_BID = 2000000000;
public User BidUser;
public AuctionEntry AuctionItem;
public int BidAmount;
public void PlaceBid(int bidAmount)
{
if(BidUser.HorseInventory.HorseList.Length >= BidUser.MaxHorses)
{
byte[] tooManyHorses = PacketBuilder.CreateChat(Messages.AuctionYouHaveTooManyHorses, PacketBuilder.CHAT_BOTTOM_RIGHT);
BidUser.LoggedinClient.SendPacket(tooManyHorses);
return;
}
string yourBidRaisedTo = Messages.FormatAuctionBidRaised(BidAmount, BidAmount + bidAmount);
if(BidAmount >= MAX_BID)
{
byte[] maxBidReached = PacketBuilder.CreateChat(Messages.AuctionBidMax, PacketBuilder.CHAT_BOTTOM_RIGHT);
BidUser.LoggedinClient.SendPacket(maxBidReached);
return;
}
if (BidAmount + bidAmount > BidUser.Money && (AuctionItem.OwnerId != BidUser.Id))
{
byte[] cantAffordBid = PacketBuilder.CreateChat(Messages.AuctionCantAffordBid, PacketBuilder.CHAT_BOTTOM_RIGHT);
BidUser.LoggedinClient.SendPacket(cantAffordBid);
return;
}
BidAmount += bidAmount;
if(BidAmount > MAX_BID) // no u
{
yourBidRaisedTo = Messages.FormatAuctionBidRaised(BidAmount, MAX_BID);
BidAmount = MAX_BID;
}
if (BidAmount > AuctionItem.HighestBid)
{
foreach(Auction room in AuctionRooms)
{
foreach(Auction.AuctionEntry entry in room.AuctionEntries)
{
if(entry.RandomId != AuctionItem.RandomId && entry.HighestBidder == BidUser.Id)
{
byte[] cantWinTooMuch = PacketBuilder.CreateChat(Messages.AuctionOnlyOneWinningBidAllowed, PacketBuilder.CHAT_BOTTOM_RIGHT);
BidUser.LoggedinClient.SendPacket(cantWinTooMuch);
return;
}
}
}
int oldBid = AuctionItem.HighestBid;
AuctionItem.HighestBid = BidAmount;
if(AuctionItem.HighestBidder != BidUser.Id && oldBid > 0)
{
if (GameServer.IsUserOnline(AuctionItem.HighestBidder))
{
User oldBidder = GameServer.GetUserById(AuctionItem.HighestBidder);
byte[] outbidMessage = PacketBuilder.CreateChat(Messages.FormatAuctionYourOutbidBy(BidUser.Username, AuctionItem.HighestBid), PacketBuilder.CHAT_BOTTOM_RIGHT);
oldBidder.LoggedinClient.SendPacket(outbidMessage);
}
}
AuctionItem.HighestBidder = BidUser.Id;
yourBidRaisedTo += Messages.AuctionTopBid;
}
else
{
yourBidRaisedTo += Messages.AuctionExistingBidHigher;
}
byte[] bidPlacedMsg = PacketBuilder.CreateChat(yourBidRaisedTo, PacketBuilder.CHAT_BOTTOM_RIGHT);
BidUser.LoggedinClient.SendPacket(bidPlacedMsg);
}
}
public class AuctionEntry
{
public AuctionEntry(int timeRemaining, int highestBid, int highestBidder, int randomId = -1)
{
RandomId = RandomID.NextRandomId(randomId);
this.timeRemaining = timeRemaining;
this.highestBid = highestBid;
this.highestBidder = highestBidder;
}
public HorseInstance Horse;
public int OwnerId;
private List<AuctionBid> bidders = new List<AuctionBid>();
public AuctionBid[] Bidders
{
get
{
return bidders.ToArray();
}
}
public bool Completed
{
get
{
return done;
}
set
{
done = value;
if(done)
{
Horse.Owner = highestBidder;
Horse.Hidden = false;
if(OwnerId == highestBidder)
{
if(GameServer.IsUserOnline(OwnerId))
{
User auctionRunner = GameServer.GetUserById(highestBidder);
auctionRunner.HorseInventory.UnHide(Horse.RandomId);
byte[] notSold = PacketBuilder.CreateChat(Messages.AuctionNoHorseBrought, PacketBuilder.CHAT_BOTTOM_RIGHT);
auctionRunner.LoggedinClient.SendPacket(notSold);
}
return;
}
if(GameServer.IsUserOnline(highestBidder))
{
User userWon = GameServer.GetUserById(highestBidder);
byte[] wonAuction = PacketBuilder.CreateChat(Messages.FormatAuctionBroughtHorse(highestBid), PacketBuilder.CHAT_BOTTOM_RIGHT);
userWon.LoggedinClient.SendPacket(wonAuction);
userWon.TakeMoney(highestBid);
userWon.HorseInventory.AddHorse(Horse, false);
}
else
{
Database.SetPlayerMoney(Database.GetPlayerMoney(highestBidder) - highestBid, highestBidder);
}
if(GameServer.IsUserOnline(OwnerId))
{
User userSold = GameServer.GetUserById(OwnerId);
byte[] horseSold = PacketBuilder.CreateChat(Messages.FormatAuctionHorseSold(highestBid), PacketBuilder.CHAT_BOTTOM_RIGHT);
userSold.LoggedinClient.SendPacket(horseSold);
userSold.AddMoney(highestBid);
userSold.HorseInventory.DeleteHorse(Horse, false);
}
else
{
Database.SetPlayerMoney(Database.GetPlayerMoney(OwnerId) + highestBid, OwnerId);
}
}
Database.SetAuctionDone(RandomId, done);
foreach(AuctionBid bid in Bidders) // Cleanup some stuffs
{
if(bid.BidUser != null)
bid.BidUser.RemoveBid(bid);
}
bidders.Clear();
}
}
public void AddBid(AuctionBid bid)
{
bidders.Add(bid);
}
public void Bid(User bidder, int bidAmount)
{
foreach(AuctionBid bid in bidder.Bids)
{
if (bid.AuctionItem.RandomId == this.RandomId)
{
bid.PlaceBid(bidAmount);
auctionRoomPlacedIn.UpdateAuctionRoom();
return;
}
}
AuctionBid newBid = new AuctionBid();
newBid.AuctionItem = this;
newBid.BidUser = bidder;
if (HighestBidder == bidder.Id)
newBid.BidAmount = HighestBid;
else
newBid.BidAmount = 0;
newBid.PlaceBid(bidAmount);
bidder.AddBid(newBid);
bidders.Add(newBid);
auctionRoomPlacedIn.UpdateAuctionRoom();
}
public Auction auctionRoomPlacedIn;
public int RandomId;
private int timeRemaining;
private bool done;
private int highestBid;
private int highestBidder;
public int TimeRemaining
{
get
{
return timeRemaining;
}
set
{
timeRemaining = value;
Database.SetAuctionTimeout(RandomId, value);
}
}
public int HighestBid
{
get
{
return highestBid;
}
set
{
highestBid = value;
Database.SetAuctionHighestBid(RandomId, value);
}
}
public int HighestBidder
{
get
{
return highestBidder;
}
set
{
highestBidder = value;
Database.SetAuctionHighestBidder(RandomId, value);
}
}
}
public void UpdateAuctionRoom()
{
World.SpecialTile[] tiles = World.GetSpecialTilesByName("AUCTION-" + this.RoomId.ToString());
foreach (World.SpecialTile tile in tiles)
{
GameServer.UpdateAreaForAll(tile.X, tile.Y, true);
}
}
public void DeleteEntry(AuctionEntry entry)
{
Database.DeleteAuctionRoom(entry.RandomId);
auctionEntries.Remove(entry);
}
public void AddExistingEntry(AuctionEntry entry)
{
auctionEntries.Add(entry);
}
public void AddEntry(AuctionEntry entry)
{
entry.auctionRoomPlacedIn = this;
Database.AddAuctionRoom(entry, this.RoomId);
auctionEntries.Add(entry);
}
private List<AuctionEntry> auctionEntries;
public int RoomId;
public AuctionEntry[] AuctionEntries
{
get
{
return auctionEntries.ToArray();
}
}
public bool HasAuctionEntry(int randomId)
{
foreach (AuctionEntry entry in AuctionEntries)
{
if (entry.RandomId == randomId)
{
return true;
}
}
return false;
}
public AuctionEntry GetAuctionEntry(int randomId)
{
foreach(AuctionEntry entry in AuctionEntries)
{
if(entry.RandomId == randomId)
{
return entry;
}
}
throw new KeyNotFoundException("Auction Entry with RandomID: " + randomId + " NOT FOUND");
}
public bool HasUserPlacedAuctionAllready(User user)
{
foreach(AuctionEntry entry in AuctionEntries)
{
if (entry.OwnerId == user.Id)
return true;
}
return false;
}
public static Auction GetAuctionRoomById(int roomId)
{
foreach(Auction auction in AuctionRooms)
{
if(auction.RoomId == roomId)
{
return auction;
}
}
throw new KeyNotFoundException("Auction with roomID " + roomId + " NOT FOUND!");
}
public static void LoadAllAuctionRooms()
{
foreach(World.SpecialTile tile in World.SpecialTiles)
{
if(tile.Code != null)
{
if(tile.Code.StartsWith("AUCTION-"))
{
int code = int.Parse(tile.Code.Split('-')[1]);
Auction loadAuctionRoom = new Auction(code);
auctionRooms.Add(loadAuctionRoom);
Logger.InfoPrint("Loading Auction Room: " + code.ToString());
}
}
}
}
}
}

View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Services
{
public class Barn
{
public Barn(int id, double tiredCost, double hungerCost, double thirstCost)
{
this.Id = id;
this.TiredCost = tiredCost;
this.HungerCost = hungerCost;
this.ThirstCost = thirstCost;
barns.Add(this);
}
private static List<Barn> barns = new List<Barn>();
public static Barn[] Barns
{
get
{
return barns.ToArray();
}
}
public int Id;
public double TiredCost;
public double HungerCost;
public double ThirstCost;
public int CalculatePrice(int tiredness, int hunger, int thirst)
{
double tiredPrice = (1000.0 - (double)tiredness) * TiredCost;
double hungerPrice = (1000.0 - (double)hunger) * HungerCost;
double thirstPrice = (1000.0 - (double)thirst) * ThirstCost;
return Convert.ToInt32(Math.Round(tiredPrice + hungerPrice + thirstPrice));
}
public static Barn GetBarnById(int id)
{
foreach (Barn barn in Barns)
if (barn.Id == id)
return barn;
throw new KeyNotFoundException("Barn id: " + id.ToString() + " Not found!");
}
}
}

View file

@ -0,0 +1,42 @@
using System.Collections.Generic;
namespace HISP.Game.Services
{
public class Farrier
{
private static List<Farrier> farriers = new List<Farrier>();
public static Farrier[] Farriers
{
get
{
return farriers.ToArray();
}
}
public int Id;
public int SteelShoesAmount;
public int SteelCost;
public int IronShoesAmount;
public int IronCost;
public Farrier(int id, int steelShoesInc, int steelCost, int ironShoesInc, int ironCost)
{
this.Id = id;
this.SteelShoesAmount = steelShoesInc;
this.SteelCost = steelCost;
this.IronShoesAmount = ironShoesInc;
this.IronCost = ironCost;
farriers.Add(this);
}
public static Farrier GetFarrierById(int id)
{
foreach (Farrier farrier in Farriers)
if (farrier.Id == id)
return farrier;
throw new KeyNotFoundException("No farrier with id: " + id + " found.");
}
}
}

View file

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
namespace HISP.Game.Services
{
public class Groomer
{
private static List<Groomer> groomers = new List<Groomer>();
public static Groomer[] Groomers
{
get
{
return groomers.ToArray();
}
}
public Groomer(int id, double price, int max)
{
Id = id;
PriceMultiplier = price;
Max = max;
groomers.Add(this);
}
public int Id;
public double PriceMultiplier;
public int Max;
public int CalculatePrice(int groom)
{
double price = ((double)Max - (double)groom) * PriceMultiplier;
return Convert.ToInt32(Math.Round(price));
}
public static Groomer GetGroomerById(int id)
{
foreach (Groomer groomer in Groomers)
{
if (id == groomer.Id)
return groomer;
}
throw new KeyNotFoundException("Groomer with id: " + id + " Not found.");
}
}
}

View file

@ -0,0 +1,86 @@
using HISP.Player;
using HISP.Game.Items;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Services
{
public class Inn
{
private static List<Inn> listInns = new List<Inn>();
public static Inn[] Inns
{
get
{
return listInns.ToArray();
}
}
public int Id;
public Item.ItemInformation[] RestsOffered;
public Item.ItemInformation[] MealsOffered;
public int BuyPercentage;
public int CalculateBuyCost(Item.ItemInformation item)
{
return Convert.ToInt32(Math.Floor((float)item.SellPrice * (100.0 / (float)BuyPercentage)));
}
public Item.ItemInformation GetStockedItem(int itemId)
{
// Check if inn stock..
foreach(Item.ItemInformation offering in RestsOffered)
{
if (offering.Id == itemId)
return offering;
}
foreach (Item.ItemInformation offering in MealsOffered)
{
if (offering.Id == itemId)
return offering;
}
throw new KeyNotFoundException("Item is not stocked by this inn.");
}
public Inn(int id, int[] restsOffered, int[] mealsOffered, int buyPercentage)
{
Id = id;
List<Item.ItemInformation> itemInfos = new List<Item.ItemInformation>();
foreach(int itemId in restsOffered)
{
itemInfos.Add(Item.GetItemById(itemId));
}
RestsOffered = itemInfos.ToArray();
itemInfos.Clear();
foreach (int itemId in mealsOffered)
{
itemInfos.Add(Item.GetItemById(itemId));
}
MealsOffered = itemInfos.ToArray();
itemInfos.Clear();
itemInfos = null;
BuyPercentage = buyPercentage;
listInns.Add(this);
}
public static Inn GetInnById(int id)
{
foreach (Inn inn in Inns)
if (inn.Id == id)
return inn;
throw new KeyNotFoundException("Inn " + id + " doesnt exist.");
}
}
}

View file

@ -0,0 +1,68 @@
using HISP.Game.Horse;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Services
{
public class Pawneer
{
public Pawneer(int breedId, int basePrice)
{
BreedId = breedId;
BasePrice = basePrice;
}
private static List<Pawneer> pawneerPriceModels = new List<Pawneer>();
private static Pawneer[] PawneerPriceModels
{
get
{
return pawneerPriceModels.ToArray();
}
}
public static void AddPawneerPriceModel(Pawneer pawneerPrice)
{
pawneerPriceModels.Add(pawneerPrice);
}
public int BreedId;
public int BasePrice;
public static int GetPawneerBasePriceForHorse(HorseInfo.Breed breed)
{
foreach (Pawneer ppm in PawneerPriceModels)
{
if (ppm.BreedId == breed.Id)
{
return ppm.BasePrice;
}
}
throw new Exception("No pawneeer base price found >_> for breed #" + breed.Id + " " + breed.Name);
}
public static int CalculateTotalPrice(HorseInstance horse)
{
HorseInfo.StatCalculator speedStat = new HorseInfo.StatCalculator(horse, HorseInfo.StatType.SPEED);
HorseInfo.StatCalculator strengthStat = new HorseInfo.StatCalculator(horse, HorseInfo.StatType.STRENGTH);
HorseInfo.StatCalculator conformationStat = new HorseInfo.StatCalculator(horse, HorseInfo.StatType.CONFORMATION);
HorseInfo.StatCalculator agilityStat = new HorseInfo.StatCalculator(horse, HorseInfo.StatType.AGILITY);
HorseInfo.StatCalculator enduranceStat = new HorseInfo.StatCalculator(horse, HorseInfo.StatType.ENDURANCE);
int basePrice = GetPawneerBasePriceForHorse(horse.Breed);
int additionalPrice = speedStat.BreedOffset * 350;
additionalPrice += strengthStat.BreedOffset * 350;
additionalPrice += conformationStat.BreedOffset * 350;
additionalPrice += agilityStat.BreedOffset * 350;
additionalPrice += enduranceStat.BreedOffset * 350;
additionalPrice += horse.BasicStats.Health * 40;
additionalPrice += horse.BasicStats.Shoes * 20;
int price = basePrice + additionalPrice;
return price;
}
}
}

View file

@ -0,0 +1,72 @@
using HISP.Game.Inventory;
using HISP.Server;
using HISP.Game.Items;
using System;
using System.Collections.Generic;
namespace HISP.Game.Services
{
public class Shop
{
public int Id;
public string[] BuysItemTypes;
public int BuyPricePercentage;
public int SellPricePercentage;
public ShopInventory Inventory;
public Shop(int[] infiniteStocks, int id)
{
this.Inventory = new ShopInventory(this);
this.Id = id;
foreach (int stock in infiniteStocks)
{
if (Item.ItemIdExist(stock))
this.Inventory.AddInfinity(Item.GetItemById(stock));
else
Logger.WarnPrint("Item ID: " + stock + " Does not exist.");
}
ItemInstance[] instances = Database.GetShopInventory(this.Id);
foreach (ItemInstance instance in instances)
{
this.Inventory.Add(instance, false);
}
Shop.ShopList.Add(this);
}
public UInt64 CalculateBuyCost(Item.ItemInformation item)
{
return Convert.ToUInt64(Math.Round((double)item.SellPrice * (100.0 / (double)BuyPricePercentage)));
}
public UInt64 CalculateSellCost(Item.ItemInformation item)
{
return Convert.ToUInt64(Math.Round((double)item.SellPrice * (100.0 / (double)SellPricePercentage)));
}
public bool CanSell(Item.ItemInformation item)
{
foreach(string ItemType in BuysItemTypes)
{
if(ItemType == item.Type)
{
return true;
}
}
return false;
}
// Static Functions
public static List<Shop> ShopList = new List<Shop>();
public static Shop GetShopById(int id)
{
foreach(Shop shop in ShopList)
{
if (shop.Id == id)
return shop;
}
throw new KeyNotFoundException("no shop with id: " + id + " found.");
}
}
}

View file

@ -0,0 +1,27 @@
using System.Collections.Generic;
namespace HISP.Game.Services
{
public class Trainer
{
public static List<Trainer> Trainers = new List<Trainer>();
public int Id;
public string ImprovesStat;
public int ImprovesAmount;
public int ThirstCost;
public int MoodCost;
public int HungerCost;
public int MoneyCost;
public int ExperienceGained;
public static Trainer GetTrainerById(int id)
{
foreach (Trainer trainer in Trainers)
if (trainer.Id == id)
return trainer;
throw new KeyNotFoundException("Trainer " + id + " not found");
}
}
}

View file

@ -0,0 +1,53 @@
using System.Collections.Generic;
namespace HISP.Game.Services
{
public class Transport
{
public struct TransportLocation
{
public int Id;
public int Cost;
public int GotoX;
public int GotoY;
public string Type;
public string LocationTitle;
}
public struct TransportPoint
{
public int X;
public int Y;
public int[] Locations;
}
public static List<TransportPoint> TransportPoints = new List<TransportPoint>();
public static List<TransportLocation> TransportLocations = new List<TransportLocation>();
public static TransportPoint GetTransportPoint(int x, int y)
{
foreach(TransportPoint transportPoint in TransportPoints)
{
if (transportPoint.X == x && transportPoint.Y == y)
{
return transportPoint;
}
}
throw new KeyNotFoundException("Cannot find transport point at x:" + x + "y:" + y);
}
public static TransportLocation GetTransportLocation(int id)
{
foreach (TransportLocation transportLocation in TransportLocations)
{
if (transportLocation.Id == id)
{
return transportLocation;
}
}
throw new KeyNotFoundException("Cannot find transport location at Id:" + id);
}
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Services
{
public class Vet
{
public static List<Vet> Vets = new List<Vet>();
public Vet(int id, double price)
{
Id = id;
PriceMultiplier = price;
Vets.Add(this);
}
public int Id;
public double PriceMultiplier;
public int CalculatePrice(int health)
{
double price = (1000.0 - (double)health) * PriceMultiplier;
return Convert.ToInt32(Math.Round(price));
}
public static Vet GetVetById(int id)
{
foreach(Vet vet in Vets)
{
if (id == vet.Id)
return vet;
}
throw new KeyNotFoundException("Vet with id: " + id + " Not found.");
}
}
}

View file

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Services
{
public class Workshop
{
public Workshop()
{
craftableItems = new List<CraftableItem>();
}
public class RequiredItem
{
public int RequiredItemId;
public int RequiredItemCount;
}
public class CraftableItem
{
public CraftableItem()
{
requiredItems = new List<RequiredItem>();
}
public int Id;
public int GiveItemId;
public int MoneyCost;
private List<RequiredItem> requiredItems;
public void AddRequiredItem(RequiredItem item)
{
requiredItems.Add(item);
}
public RequiredItem[] RequiredItems
{
get
{
return requiredItems.ToArray();
}
}
}
public int X;
public int Y;
private List<CraftableItem> craftableItems;
private static List<Workshop> workshops = new List<Workshop>();
public void AddCraftableItem(CraftableItem craftItem)
{
craftableItems.Add(craftItem);
}
public static void AddWorkshop(Workshop wkShop)
{
workshops.Add(wkShop);
}
public CraftableItem[] CraftableItems
{
get
{
return craftableItems.ToArray();
}
}
public static Workshop[] Workshops
{
get
{
return workshops.ToArray();
}
}
public static Workshop GetWorkshopAt(int x, int y)
{
foreach(Workshop wkShop in Workshops)
{
if(wkShop.X == x && wkShop.Y == y)
{
return wkShop;
}
}
throw new KeyNotFoundException("No workshop found.");
}
public static bool CraftIdExists(int id)
{
try
{
GetCraftId(id);
return true;
}
catch(KeyNotFoundException)
{
return false;
}
}
public static CraftableItem GetCraftId(int id)
{
foreach(Workshop wkShop in Workshops)
{
foreach(CraftableItem crftItem in wkShop.CraftableItems)
{
if (crftItem.Id == id)
return crftItem;
}
}
throw new KeyNotFoundException("No craft id " + id + " was found.");
}
}
}