Permalink
Browse files

Lot buy should work

However, coordinates are currently never in range.
  • Loading branch information...
1 parent 328fc90 commit 1a4257bb6c21d9ef9d017c232deffc07ad2bcd68 Mats Vederhus committed Jul 25, 2015
@@ -207,6 +207,7 @@ public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P
characterModel.BodyOutfitID = (long)Char.BodyOutfitID;
characterModel.AccountID = AccountID;
characterModel.AppearanceType = (int)Char.Appearance;
+ characterModel.Money = NetworkFacade.INITIAL_MONEY;
NetworkFacade.CurrentSession.AddPlayer(Client, characterModel);
@@ -286,6 +287,8 @@ public static void HandleCityToken(NetworkClient Client, ProcessedPacket P)
SuccessPacket.WriteInt32(Ho.Cost);
}
+ SuccessPacket.WriteInt32(Char.Money);
+
Client.SendEncrypted((byte)PacketType.CITY_TOKEN, SuccessPacket.ToArray());
}
/*else
@@ -447,6 +450,10 @@ public static void HandleLotPurchaseRequest(NetworkClient Client, ProcessedPacke
Char.HouseHouse.X = X;
Char.HouseHouse.Y = Y;
Char.Money -= NetworkFacade.LOT_COST;
+
+ PacketStream SuccessPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, 0);
+ SuccessPacket.WriteInt32(Char.Money);
+ Client.SendEncrypted((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, SuccessPacket.ToArray());
}
else
{
@@ -36,6 +36,7 @@ public class NetworkFacade
public static Terrain.Terrain CurrentTerrain = new Terrain.Terrain();
public const int LOT_COST = 2000; //Hardcoded for now...
+ public const int INITIAL_MONEY = 5000; //Hardcoded for now...
/// <summary>
/// Thread-safe method for getting client tokens.
@@ -286,6 +286,7 @@ public static void HandleCharacterInfoRequest(NetworkClient Client, ProcessedPac
PacketWriter.Write((ulong)avatar.CityMap);
PacketWriter.Write((string)avatar.CityIp);
PacketWriter.Write((int)avatar.CityPort);
+ PacketWriter.Write((int)avatar.Money);
}
}
@@ -404,6 +405,7 @@ public static void HandleCharacterCreate(NetworkClient Client, ProcessedPacket P
Char.CityMap = (long)P.ReadUInt64();
Char.CityIp = P.ReadString();
Char.CityPort = P.ReadInt32();
+ Char.Money = NetworkFacade.INITIAL_MONEY;
//These are going into DB, so be nazi. Sieg heil!
if (Char.Name == string.Empty || Char.Sex == string.Empty ||
@@ -12,6 +12,8 @@ class NetworkFacade
public static CityServerListener CServerListener;
public static Listener ClientListener;
+ public const int INITIAL_MONEY = 5000; //Hardcoded for now...
+
public static ECDiffieHellmanCng ServerKey = new ECDiffieHellmanCng();
public static byte[] ServerPublicKey = ServerKey.PublicKey.ToByteArray();
}
@@ -326,12 +326,23 @@ public void Initialize(String CityName, CityDataRetriever cityData)
Network.NetworkFacade.Controller.OnLotUnbuildable += new Network.OnLotUnbuildableDelegate(Controller_OnLotUnbuildable);
Network.NetworkFacade.Controller.OnLotCost += new Network.OnLotCostDelegate(Controller_OnLotCost);
Network.NetworkFacade.Controller.OnLotPurchaseFailed += Controller_OnLotPurchaseFailed;
+ Network.NetworkFacade.Controller.OnLotPurchaseSuccessful += Controller_OnLotPurchaseSuccessful;
m_PacketTimer.Elapsed += new ElapsedEventHandler(m_PacketTimer_Elapsed);
m_PacketTimer.AutoReset = true;
m_PacketTimer.Start();
}
+ private void Controller_OnLotPurchaseSuccessful(int Money)
+ {
+ CoreGameScreen CurrentUIScr = (CoreGameScreen)GameFacade.Screens.CurrentUIScreen;
+
+ PlayerAccount.Money = Money;
+ CurrentUIScr.ucp.MoneyText.Caption = Money.ToString();
+
+ //TODO: Add popup dialog.
+ }
+
#region Network handlers
private void Controller_OnLotUnbuildable()
@@ -184,6 +184,7 @@ public CoreGameScreen()
ucp.Y = ScreenHeight - 210;
ucp.SetInLot(false);
ucp.UpdateZoomButton();
+ ucp.MoneyText.Caption = PlayerAccount.Money.ToString();
this.Add(ucp);
gizmo = new UIGizmo();
@@ -49,6 +49,7 @@ namespace TSOClient.Network
public delegate void OnLotCostDelegate(LotTileEntry Entry);
public delegate void OnLotUnbuildableDelegate();
public delegate void OnLotPurchaseFailedDelegate(TransactionEvent e);
+ public delegate void OnLotPurchaseSuccessfulDelegate(int Money);
/// <summary>
/// Handles moving between various network states, e.g.
@@ -76,6 +77,7 @@ public class NetworkController
public event OnLotCostDelegate OnLotCost;
public event OnLotUnbuildableDelegate OnLotUnbuildable;
public event OnLotPurchaseFailedDelegate OnLotPurchaseFailed;
+ public event OnLotPurchaseSuccessfulDelegate OnLotPurchaseSuccessful;
public NetworkController()
{
@@ -367,6 +369,10 @@ public void _OnNewCity(NetworkClient Client, ProcessedPacket Packet)
if (OnNewCityServer != null)
OnNewCityServer();
+ else
+ {
+ //TODO: Error handling...
+ }
}
public void _OnCityServerOffline(NetworkClient Client, ProcessedPacket Packet)
@@ -384,6 +390,10 @@ public void _OnTimeOfDay(NetworkClient Client, ProcessedPacket Packet)
if (OnNewTimeOfDay != null)
OnNewTimeOfDay(CurrentTime);
+ else
+ {
+ //TODO: Error handling...
+ }
}
/// <summary>
@@ -393,7 +403,12 @@ public void _OnLotCost(NetworkClient Client, ProcessedPacket Packet)
{
LotTileEntry Entry = UIPacketHandlers.OnLotCostResponse(Client, Packet);
- OnLotCost(Entry);
+ if(OnLotCost != null)
+ OnLotCost(Entry);
+ else
+ {
+ //TODO: Error handling...
+ }
}
/// <summary>
@@ -402,15 +417,38 @@ public void _OnLotCost(NetworkClient Client, ProcessedPacket Packet)
public void _OnLotBuyFailed(NetworkClient Client, ProcessedPacket Packet)
{
UIPacketHandlers.OnLotPurchaseFailed(Client, Packet);
- OnLotPurchaseFailed(new TransactionEvent(EventCodes.TRANSACTION_RESULT) { Success = false });
+
+ if(OnLotPurchaseFailed != null)
+ OnLotPurchaseFailed(new TransactionEvent(EventCodes.TRANSACTION_RESULT) { Success = false });
+ else
+ {
+ //TODO: Error handling...
+ }
}
/// <summary>
/// A lot was deemed unbuildable/unpurchasable by city server.
/// </summary>
public void _OnLotUnbuildable(NetworkClient Client, ProcessedPacket Packet)
{
- OnLotUnbuildable();
+ if(OnLotUnbuildable != null)
+ OnLotUnbuildable();
+ else
+ {
+ //TODO: Error handling...
+ }
+ }
+
+ public void _OnLotPurchaseSuccessful(NetworkClient Client, ProcessedPacket Packet)
+ {
+ int Money = UIPacketHandlers.OnLotPurchaseSuccessful(Client, Packet);
+
+ if (OnLotPurchaseSuccessful != null)
+ OnLotPurchaseSuccessful(Money);
+ else
+ {
+ //TODO: Error handling...
+ }
}
/// <summary>
@@ -105,6 +105,7 @@ static NetworkFacade()
PacketHandlers.Register((byte)PacketType.LOT_COST, true, 0, new OnPacketReceive(Controller._OnLotCost));
PacketHandlers.Register((byte)PacketType.LOT_UNBUILDABLE, true, 0, new OnPacketReceive(Controller._OnLotUnbuildable));
PacketHandlers.Register((byte)PacketType.LOT_PURCHASE_FAILED, true, 0, new OnPacketReceive(Controller._OnLotBuyFailed));
+ PacketHandlers.Register((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, true, 0, new OnPacketReceive(Controller._OnLotPurchaseSuccessful));
}
}
}
@@ -366,6 +366,8 @@ public static CityTransferStatus OnCityTokenResponse(NetworkClient Client, Proce
}
}
+ PlayerAccount.Money = Packet.ReadInt32();
+
lock(TSOClient.Code.GameFacade.CDataRetriever.LotTileData)
TSOClient.Code.GameFacade.CDataRetriever.LotTileData = TileEntries;
@@ -543,5 +545,14 @@ public static void OnLotPurchaseFailed(NetworkClient Client, ProcessedPacket Pac
break;
}
}
+
+ /// <summary>
+ /// Lot purchase was successful.
+ /// </summary>
+ /// <returns>New amount of money for character sent by server.</returns>
+ public static int OnLotPurchaseSuccessful(NetworkClient Client, ProcessedPacket Packet)
+ {
+ return Packet.ReadInt32();
+ }
}
}
@@ -34,5 +34,7 @@ class PlayerAccount
//Token received from LoginServer when transitioning to a CityServer.
public static string CityToken = "";
+
+ public static int Money = 0; //Received from server.
}
}

0 comments on commit 1a4257b

Please sign in to comment.