mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-21 12:19:15 +12:00
Finish Auctions? (finally??)
This commit is contained in:
parent
0f95462294
commit
69e7ef1baa
10 changed files with 235 additions and 69 deletions
|
@ -6,10 +6,10 @@ namespace HISP.Game.Horse
|
|||
{
|
||||
public 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, int leaseTimer=0, bool loadHidden=false)
|
||||
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, int leaseTimer=0, bool loadHidden=false, int loadOwner=0)
|
||||
{
|
||||
RandomId = RandomID.NextRandomId(randomId);
|
||||
Owner = 0;
|
||||
owner = loadOwner;
|
||||
if(loadName == null)
|
||||
{
|
||||
|
||||
|
@ -61,7 +61,19 @@ namespace HISP.Game.Horse
|
|||
}
|
||||
public int Leaser;
|
||||
public int RandomId;
|
||||
public int Owner;
|
||||
public int owner;
|
||||
public int Owner
|
||||
{
|
||||
get
|
||||
{
|
||||
return owner;
|
||||
}
|
||||
set
|
||||
{
|
||||
owner = value;
|
||||
Database.SetHorseOwner(RandomId, owner);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Hidden
|
||||
{
|
||||
|
|
|
@ -30,6 +30,17 @@ namespace HISP.Game.Inventory
|
|||
Database.LoadHorseInventory(this, baseUser.Id);
|
||||
}
|
||||
|
||||
public void UnHide(int randomId)
|
||||
{
|
||||
foreach(HorseInstance inst in horsesList)
|
||||
{
|
||||
if (inst.RandomId == randomId)
|
||||
{
|
||||
inst.Hidden = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void AddHorse(HorseInstance horse, bool addToDb=true)
|
||||
{
|
||||
if (HorseList.Length + 1 > baseUser.MaxHorses)
|
||||
|
@ -41,9 +52,10 @@ namespace HISP.Game.Inventory
|
|||
horsesList.Add(horse);
|
||||
}
|
||||
|
||||
public void DeleteHorse(HorseInstance horse)
|
||||
public void DeleteHorse(HorseInstance horse, bool removeFromDb=true)
|
||||
{
|
||||
Database.RemoveHorse(horse.RandomId);
|
||||
if(removeFromDb)
|
||||
Database.RemoveHorse(horse.RandomId);
|
||||
horsesList.Remove(horse);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,10 @@ namespace HISP.Game
|
|||
public static string AuctionListHorse;
|
||||
|
||||
public static string AuctionHorseListEntryFormat;
|
||||
public static string AuctionHorseViewButton;
|
||||
public static string AuctionHorseIsTacked;
|
||||
|
||||
public static string AuctionBidMax;
|
||||
public static string AuctionBidRaisedFormat;
|
||||
public static string AuctionTopBid;
|
||||
public static string AuctionExistingBidHigher;
|
||||
|
@ -31,6 +33,7 @@ namespace HISP.Game
|
|||
public static string AuctionYouveBeenOutbidFormat;
|
||||
public static string AuctionCantAffordBid;
|
||||
public static string AuctionCantAffordAuctionFee;
|
||||
public static string AuctionOneHorsePerPlayer;
|
||||
|
||||
public static string AuctionYouBroughtAHorseFormat;
|
||||
public static string AuctionNoHorseBrought;
|
||||
|
@ -41,6 +44,8 @@ namespace HISP.Game
|
|||
public static string AuctionNotSold;
|
||||
public static string AuctionGoingToFormat;
|
||||
|
||||
public static string AuctionNoOtherTransactionAllowed;
|
||||
|
||||
// Warp Command
|
||||
public static string SuccessfullyWarpedToLocation;
|
||||
public static string SuccessfullyWarpedToPlayer;
|
||||
|
@ -894,7 +899,7 @@ namespace HISP.Game
|
|||
|
||||
public static string FormatAuctionSoldTo(string playerName, int money)
|
||||
{
|
||||
return AuctionSoldToFormat.Replace("%PLAYERNAME%", playerName).Replace("%MONEY%", money.ToString("N0", CultureInfo.InvariantCulture));
|
||||
return AuctionSoldToFormat.Replace("%PLAYERNAME%", playerName).Replace("%PRICE%", money.ToString("N0", CultureInfo.InvariantCulture));
|
||||
}
|
||||
public static string FormatAuctionGoingTo(int timeRemaining, string winningPlayer, int winningBid, int auctionRandomId)
|
||||
{
|
||||
|
@ -920,11 +925,15 @@ namespace HISP.Game
|
|||
{
|
||||
return AuctionHorseListEntryFormat.Replace("%HORSENAME%", horseName).Replace("%TACKEDORNO%", tacked ? Messages.AuctionHorseIsTacked : "").Replace("%RANDOMID%", randomId.ToString());
|
||||
}
|
||||
public static string FormatAuctionHorseEntry(string username, string color, string breedName, string gender, int experience, int horseRandomId)
|
||||
public static string FormatAuctionHorseEntry(string username, string color, string breedName, string gender, int experience, string lookButton)
|
||||
{
|
||||
return AuctionHorseEntryFormat.Replace("%USERNAME%", username).Replace("%COLOR%", color).Replace("%BREED%", breedName).Replace("%GENDER%", gender).Replace("%EXP%", experience.ToString("N0", CultureInfo.InvariantCulture)).Replace("%RANDOMID%", horseRandomId.ToString());
|
||||
return AuctionHorseEntryFormat.Replace("%USERNAME%", username).Replace("%COLOR%", color).Replace("%BREED%", breedName).Replace("%GENDER%", gender).Replace("%EXP%", experience.ToString("N0", CultureInfo.InvariantCulture)).Replace("%LOOKBUTTON%", lookButton);
|
||||
|
||||
}
|
||||
public static string FormatAuctionViewHorseButton(int randomId)
|
||||
{
|
||||
return AuctionHorseViewButton.Replace("%RANDOMID%", randomId.ToString());
|
||||
}
|
||||
public static string FormatAuctionPlayersHere(string usernames)
|
||||
{
|
||||
return AuctionPlayersHereFormat.Replace("%USERNAMES%", usernames);
|
||||
|
|
|
@ -1469,7 +1469,7 @@ namespace HISP.Game
|
|||
message += Messages.AuctionsRunning;
|
||||
foreach(Auction.AuctionEntry entry in auction.AuctionEntries.ToArray())
|
||||
{
|
||||
message += Messages.FormatAuctionHorseEntry(Database.GetUsername(entry.OwnerId), entry.Horse.Color, entry.Horse.Breed.Name, entry.Horse.Gender, entry.Horse.BasicStats.Experience, entry.Horse.RandomId);
|
||||
message += Messages.FormatAuctionHorseEntry(Database.GetUsername(entry.OwnerId), entry.Horse.Color, entry.Horse.Breed.Name, entry.Horse.Gender, entry.Horse.BasicStats.Experience, entry.Completed ? "" : Messages.FormatAuctionViewHorseButton(entry.Horse.RandomId));
|
||||
if (!entry.Completed)
|
||||
message += Messages.FormatAuctionGoingTo(entry.TimeRemaining, Database.GetUsername(entry.HighestBidder), entry.HighestBid, entry.RandomId);
|
||||
else
|
||||
|
|
|
@ -18,19 +18,44 @@ namespace HISP.Game.Services
|
|||
|
||||
public class AuctionBid
|
||||
{
|
||||
public const int MAX_BID = 2000000000;
|
||||
public User BidUser;
|
||||
public AuctionEntry AuctionItem;
|
||||
public int BidAmount;
|
||||
|
||||
|
||||
public void PlaceBid(int bidAmount)
|
||||
{
|
||||
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)
|
||||
{
|
||||
AuctionItem.HighestBid += BidAmount;
|
||||
if(AuctionItem.HighestBidder != BidUser.Id)
|
||||
int oldBid = AuctionItem.HighestBid;
|
||||
AuctionItem.HighestBid = BidAmount;
|
||||
if(AuctionItem.HighestBidder != BidUser.Id && oldBid > 0)
|
||||
{
|
||||
if (GameServer.IsUserOnline(AuctionItem.HighestBidder))
|
||||
{
|
||||
|
@ -42,7 +67,6 @@ namespace HISP.Game.Services
|
|||
|
||||
AuctionItem.HighestBidder = BidUser.Id;
|
||||
yourBidRaisedTo += Messages.AuctionTopBid;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -51,6 +75,7 @@ namespace HISP.Game.Services
|
|||
|
||||
byte[] bidPlacedMsg = PacketBuilder.CreateChat(yourBidRaisedTo, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
BidUser.LoggedinClient.SendPacket(bidPlacedMsg);
|
||||
|
||||
}
|
||||
}
|
||||
public class AuctionEntry
|
||||
|
@ -65,7 +90,8 @@ namespace HISP.Game.Services
|
|||
|
||||
public HorseInstance Horse;
|
||||
public int OwnerId;
|
||||
|
||||
public List<AuctionBid> Bidders = new List<AuctionBid>();
|
||||
|
||||
public bool Completed
|
||||
{
|
||||
get
|
||||
|
@ -77,26 +103,42 @@ namespace HISP.Game.Services
|
|||
done = value;
|
||||
if(done)
|
||||
{
|
||||
Horse.Owner = HighestBidder;
|
||||
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.Money -= highestBid;
|
||||
userWon.HorseInventory.AddHorse(Horse, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Database.SetPlayerMoney(Database.GetPlayerMoney(highestBidder) - highestBid, highestBidder);
|
||||
}
|
||||
|
||||
if(GameServer.IsUserOnline(OwnerId))
|
||||
{
|
||||
User userSold = GameServer.GetUserById(highestBidder);
|
||||
User userSold = GameServer.GetUserById(OwnerId);
|
||||
byte[] horseSold = PacketBuilder.CreateChat(Messages.FormatAuctionHorseSold(highestBid), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
userSold.LoggedinClient.SendPacket(horseSold);
|
||||
userSold.Money += highestBid;
|
||||
userSold.HorseInventory.DeleteHorse(Horse, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -104,6 +146,13 @@ namespace HISP.Game.Services
|
|||
}
|
||||
}
|
||||
Database.SetAuctionDone(RandomId, done);
|
||||
|
||||
foreach(AuctionBid bid in Bidders) // Cleanup some stuffs
|
||||
{
|
||||
if(bid.BidUser != null)
|
||||
bid.BidUser.Bids.Remove(bid);
|
||||
}
|
||||
Bidders.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -115,6 +164,7 @@ namespace HISP.Game.Services
|
|||
if (bid.AuctionItem.RandomId == this.RandomId)
|
||||
{
|
||||
bid.PlaceBid(bidAmount);
|
||||
auctionRoomPlacedIn.UpdateAuctionRoom();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -122,11 +172,17 @@ namespace HISP.Game.Services
|
|||
AuctionBid newBid = new AuctionBid();
|
||||
newBid.AuctionItem = this;
|
||||
newBid.BidUser = bidder;
|
||||
newBid.BidAmount = 0;
|
||||
if (HighestBidder == bidder.Id)
|
||||
newBid.BidAmount = HighestBid;
|
||||
else
|
||||
newBid.BidAmount = 0;
|
||||
newBid.PlaceBid(bidAmount);
|
||||
bidder.Bids.Add(newBid);
|
||||
Bidders.Add(newBid);
|
||||
auctionRoomPlacedIn.UpdateAuctionRoom();
|
||||
}
|
||||
|
||||
public Auction auctionRoomPlacedIn;
|
||||
public int RandomId;
|
||||
private int timeRemaining;
|
||||
private bool done;
|
||||
|
@ -200,6 +256,7 @@ namespace HISP.Game.Services
|
|||
|
||||
public void AddEntry(AuctionEntry entry)
|
||||
{
|
||||
entry.auctionRoomPlacedIn = this;
|
||||
Database.AddAuctionRoom(entry, this.RoomId);
|
||||
AuctionEntries.Add(entry);
|
||||
|
||||
|
@ -232,6 +289,15 @@ namespace HISP.Game.Services
|
|||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue