Auctions still dont work but i gtg.

This commit is contained in:
SilicaAndPina 2021-02-20 12:26:25 +13:00
parent cc22dbcf0b
commit 0f95462294
12 changed files with 385 additions and 44 deletions

View file

@ -52,7 +52,6 @@ namespace HISP.Game.Horse
{
Instance = horse;
timeout = despawnTimeout;
if(MapX == -1 && MapY == -1)
{
while (true)
@ -113,35 +112,47 @@ namespace HISP.Game.Horse
if (GameServer.GetUsersAt(this.X, this.Y, true, true).Length > 0)
return;
int direction = GameServer.RandomNumberGenerator.Next(0, 3);
int tryX = this.X;
int tryY = this.Y;
switch (direction)
int tries = 0;
while(true)
{
case 0:
tryX += 1;
break;
case 1:
tryX -= 1;
break;
case 2:
tryY += 1;
break;
case 3:
tryY -= 1;
break;
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 + " is stuck (cant move after 100 tries)");
break;
}
tries++;
}
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;
}
}
public void Escape()

View file

@ -37,6 +37,10 @@ namespace HISP.Game
public static string AuctionHorseSoldFormat;
public static string AuctionSoldToFormat;
public static string AuctionNotSold;
public static string AuctionGoingToFormat;
// Warp Command
public static string SuccessfullyWarpedToLocation;
public static string SuccessfullyWarpedToPlayer;
@ -888,6 +892,14 @@ namespace HISP.Game
// Click
public static string NothingInterestingHere;
public static string FormatAuctionSoldTo(string playerName, int money)
{
return AuctionSoldToFormat.Replace("%PLAYERNAME%", playerName).Replace("%MONEY%", money.ToString("N0", CultureInfo.InvariantCulture));
}
public static string FormatAuctionGoingTo(int timeRemaining, string winningPlayer, int winningBid, int auctionRandomId)
{
return AuctionGoingToFormat.Replace("%TIME%", timeRemaining.ToString()).Replace("%WINNINGPLAYER%", winningPlayer).Replace("%WINNINGBID%", winningBid.ToString("N0", CultureInfo.InvariantCulture)).Replace("%AUCTIONRANDOMID%", auctionRandomId.ToString());
}
public static string FormatAuctionHorseSold(int money)
{
return AuctionHorseSoldFormat.Replace("%MONEY%", money.ToString("N0", CultureInfo.InvariantCulture));
@ -908,9 +920,9 @@ 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, int timeRemaining, string winningPlayer, int winningBid, int auctionRandomId)
public static string FormatAuctionHorseEntry(string username, string color, string breedName, string gender, int experience, int horseRandomId)
{
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()).Replace("%TIME%", timeRemaining.ToString()).Replace("%WINNINGPLAYER%", winningPlayer).Replace("%WINNINGBID%", winningBid.ToString("N0", CultureInfo.InvariantCulture)).Replace("%AUCTIONRANDOMID%", auctionRandomId.ToString());
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());
}
public static string FormatAuctionPlayersHere(string usernames)

View file

@ -1467,9 +1467,18 @@ namespace HISP.Game
{
string message = "";
message += Messages.AuctionsRunning;
foreach(Auction.AuctionEntry entry in auction.AuctionEntries)
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, entry.TimeRemaining, Database.GetUsername(entry.HighestBidder), entry.HighestBid, entry.RandomId);
message += Messages.FormatAuctionHorseEntry(Database.GetUsername(entry.OwnerId), entry.Horse.Color, entry.Horse.Breed.Name, entry.Horse.Gender, entry.Horse.BasicStats.Experience, entry.Horse.RandomId);
if (!entry.Completed)
message += Messages.FormatAuctionGoingTo(entry.TimeRemaining, Database.GetUsername(entry.HighestBidder), entry.HighestBid, entry.RandomId);
else
{
if (entry.HighestBidder == entry.OwnerId)
message += Messages.AuctionNotSold;
else
message += Messages.FormatAuctionSoldTo(Database.GetUsername(entry.HighestBidder), entry.HighestBid);
}
}
User[] users = GameServer.GetUsersAt(user.X, user.Y, true, true);
List<string> usernames = new List<string>();

View file

@ -129,6 +129,7 @@ namespace HISP.Game
// Check Tile Type
int TileID = Map.GetTileId(x, y, false);
string TileType = Map.TerrainTiles[TileID - 1].Type;
if (TileType != this.StayOn)
return false;
@ -149,7 +150,7 @@ namespace HISP.Game
int tries = 0;
while(true)
{
int direction = GameServer.RandomNumberGenerator.Next(0, 3);
int direction = GameServer.RandomNumberGenerator.Next(0, 4);
int tryX = this.X;
int tryY = this.Y;

View file

@ -1,4 +1,5 @@
using HISP.Game.Horse;
using HISP.Player;
using HISP.Security;
using HISP.Server;
using System.Collections.Generic;
@ -14,6 +15,44 @@ namespace HISP.Game.Services
AuctionEntries = new List<AuctionEntry>();
Database.LoadAuctionRoom(this, RoomId);
}
public class AuctionBid
{
public User BidUser;
public AuctionEntry AuctionItem;
public int BidAmount;
public void PlaceBid(int bidAmount)
{
string yourBidRaisedTo = Messages.FormatAuctionBidRaised(BidAmount, BidAmount + bidAmount);
BidAmount += bidAmount;
if (BidAmount > AuctionItem.HighestBid)
{
AuctionItem.HighestBid += BidAmount;
if(AuctionItem.HighestBidder != BidUser.Id)
{
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)
@ -26,10 +65,71 @@ namespace HISP.Game.Services
public HorseInstance Horse;
public int OwnerId;
public bool Completed
{
get
{
return done;
}
set
{
done = value;
if(done)
{
Horse.Owner = HighestBidder;
Horse.Hidden = false;
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;
}
else
{
Database.SetPlayerMoney(Database.GetPlayerMoney(highestBidder) - highestBid, highestBidder);
}
if(GameServer.IsUserOnline(OwnerId))
{
User userSold = GameServer.GetUserById(highestBidder);
byte[] horseSold = PacketBuilder.CreateChat(Messages.FormatAuctionHorseSold(highestBid), PacketBuilder.CHAT_BOTTOM_RIGHT);
userSold.LoggedinClient.SendPacket(horseSold);
userSold.Money += highestBid;
}
else
{
Database.SetPlayerMoney(Database.GetPlayerMoney(OwnerId) + highestBid, OwnerId);
}
}
Database.SetAuctionDone(RandomId, done);
}
}
public void Bid(User bidder, int bidAmount)
{
foreach(AuctionBid bid in bidder.Bids)
{
if (bid.AuctionItem.RandomId == this.RandomId)
{
bid.PlaceBid(bidAmount);
return;
}
}
AuctionBid newBid = new AuctionBid();
newBid.AuctionItem = this;
newBid.BidUser = bidder;
newBid.BidAmount = 0;
newBid.PlaceBid(bidAmount);
bidder.Bids.Add(newBid);
}
public int RandomId;
private int timeRemaining;
private bool done;
private int highestBid;
private int highestBidder;
@ -43,6 +143,7 @@ namespace HISP.Game.Services
{
timeRemaining = value;
Database.SetAuctionTimeout(RandomId, value);
}
}
public int HighestBid
@ -74,10 +175,34 @@ namespace HISP.Game.Services
}
public void UpdateAuctionRoom()
{
foreach (World.SpecialTile tile in World.SpecialTiles)
{
if (tile.Code != null)
{
if (tile.Code.StartsWith("AUCTION-"))
{
int id = int.Parse(tile.Code.Split('-')[1]);
if (id == this.RoomId)
{
GameServer.UpdateAreaForAll(tile.X, tile.Y);
}
}
}
}
}
public void DeleteEntry(AuctionEntry entry)
{
Database.DeleteAuctionRoom(entry.RandomId);
AuctionEntries.Remove(entry);
}
public void AddEntry(AuctionEntry entry)
{
Database.AddAuctionRoom(entry, this.RoomId);
AuctionEntries.Add(entry);
}
public List<AuctionEntry> AuctionEntries;