Add more auction checks

This commit is contained in:
SilicaAndPina 2021-02-23 01:51:18 +13:00
parent f35456385d
commit 35a1d00dd3
8 changed files with 689 additions and 4 deletions

View file

@ -0,0 +1,43 @@
using HISP.Server;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HISP.Game.Events
{
public class RealTimeRiddle
{
public static List<RealTimeRiddle> RealTimeRiddles = new List<RealTimeRiddle>();
public RealTimeRiddle(int riddleId, string riddleText, string[] answers, int reward)
{
RiddleId = riddleId;
RiddleText = riddleText;
Answers = answers;
Reward = reward;
RealTimeRiddles.Add(this);
}
public int RiddleId;
public string RiddleText;
public string[] Answers;
public int Reward;
public static RealTimeRiddle GetRandomRiddle()
{
int randomRiddleIndex = GameServer.RandomNumberGenerator.Next(0, RealTimeRiddles.Count);
return RealTimeRiddles[randomRiddleIndex];
}
public bool CheckRiddle(string message)
{
string msgCheck = message.ToLower();
foreach(string answer in Answers)
{
if (answer.ToLower().Contains(msgCheck))
return true;
}
return false;
}
}
}

View file

@ -147,7 +147,7 @@ namespace HISP.Game.Horse
if(tries >= 100)
{
Logger.ErrorPrint("Wild Horse: " + Instance.Name + " " + Instance.Breed + " is stuck (cant move after 100 tries)");
Logger.ErrorPrint("Wild Horse: " + Instance.Name + " " + Instance.Breed.Name + " is stuck (cant move after 100 tries) at " + x.ToString() + ", " + y.ToString());
break;
}
tries++;
@ -159,8 +159,8 @@ namespace HISP.Game.Horse
{
while(true)
{
int tryX = X + GameServer.RandomNumberGenerator.Next(-15, 15);
int tryY = Y + GameServer.RandomNumberGenerator.Next(-15, 15);
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..

View file

@ -35,6 +35,9 @@ namespace HISP.Game
public static string AuctionCantAffordAuctionFee;
public static string AuctionOneHorsePerPlayer;
public static string AuctionYouHaveTooManyHorses;
public static string AuctionOnlyOneWinningBidAllowed;
public static string AuctionYouBroughtAHorseFormat;
public static string AuctionNoHorseBrought;

View file

@ -26,6 +26,13 @@ namespace HISP.Game.Services
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)
@ -35,6 +42,7 @@ namespace HISP.Game.Services
return;
}
if (BidAmount + bidAmount > BidUser.Money && (AuctionItem.OwnerId != BidUser.Id))
{
@ -53,6 +61,20 @@ namespace HISP.Game.Services
if (BidAmount > AuctionItem.HighestBid)
{
foreach(Auction room in AuctionRooms)
{
foreach(Auction.AuctionEntry entry in room.AuctionEntries)
{
if(entry.RandomId != AuctionItem.RandomId)
{
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)

View file

@ -51,8 +51,22 @@ namespace HISP.Server
string BannedPlayers = "CREATE TABLE BannedPlayers(playerId INT, ipAddress TEXT(1028), reason TEXT(1028))";
string RiddlesComplete = "CREATE TABLE RiddlesComplete(playerId INT, riddleId INT, solved TEXT(1028))";
string AuctionTable = "CREATE TABLE Auctions(roomId INT, randomId INT, horseRandomId INT, ownerId INT, timeRemaining INT, highestBid INT, highestBidder INT, Done TEXT(3))";
string SolvedRealTimeRiddle = "CREATE TABLE SolvedRealTimeRiddles(playerId INT, riddleId INT)";
string DeleteOnlineUsers = "DELETE FROM OnlineUsers";
try
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = SolvedRealTimeRiddle;
sqlCommand.ExecuteNonQuery();
sqlCommand.Dispose();
}
catch (Exception e)
{
Logger.WarnPrint(e.Message);
};
try
{
MySqlCommand sqlCommand = db.CreateCommand();
@ -496,6 +510,26 @@ namespace HISP.Server
return count >= 1;
}
}
public static int[] GetSolvedRealTimeRiddles(int playerId)
{
List<int> solvedRiddleId = new List<int>();
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = "SELECT riddleId FROM SolvedRealTimeRiddles WHERE playerId=@playerId";
sqlCommand.Parameters.AddWithValue("@playerId", playerId);
sqlCommand.Prepare();
MySqlDataReader reader = sqlCommand.ExecuteReader();
while(reader.Read())
{
solvedRiddleId.Add(reader.GetInt32(0));
}
sqlCommand.Dispose();
return solvedRiddleId.ToArray();
}
}
public static int GetRanchInvestment(int ranchId)
{
using (MySqlConnection db = new MySqlConnection(ConnectionString))

View file

@ -837,6 +837,9 @@ namespace HISP.Server
Messages.AuctionTopBid = gameData.messages.meta.auction.top_bid;
Messages.AuctionExistingBidHigher = gameData.messages.meta.auction.existing_higher;
Messages.AuctionYouHaveTooManyHorses = gameData.messages.meta.auction.you_have_too_many_horses;
Messages.AuctionOnlyOneWinningBidAllowed = gameData.messages.meta.auction.only_one_winning_bid_allowed;
Messages.AuctionOneHorsePerPlayer = gameData.messages.meta.auction.one_horse_at_a_time;
Messages.AuctionYouveBeenOutbidFormat = gameData.messages.meta.auction.outbid_by;
Messages.AuctionCantAffordBid = gameData.messages.meta.auction.cant_afford_bid;

View file

@ -16,6 +16,7 @@ using HISP.Game.Services;
using HISP.Game.Inventory;
using HISP.Game.SwfModules;
using HISP.Game.Horse;
using HISP.Game.Events;
using HISP.Game.Items;
namespace HISP.Server
@ -37,6 +38,9 @@ namespace HISP.Server
public static Random RandomNumberGenerator = new Random();
// Events
public static RealTimeRiddle ActiveRiddleEvent;
/*
* Private stuff
*/