Permalink
Browse files

Lot build almost works.

General DB error right now.
  • Loading branch information...
1 parent 4d003a7 commit 85208f704a73b84250bbb3d7d76632360fd66796 Mats Vederhus committed Jul 26, 2015
@@ -28,6 +28,31 @@ public HouseAccess(DataAccess context)
}
/// <summary>
+ /// Attempts to create a house in the DB.
+ /// </summary>
+ /// <param name="house">A House instance to add to the DB.</param>
+ /// <returns>A HouseCreationStatus indicating success or failure.</returns>
+ public HouseCreationStatus CreateHouse(House house)
+ {
+ if (house.Name.Length > 24)
+ {
+ return HouseCreationStatus.NameTooLong;
+ }
+
+ try
+ {
+ Context.Context.Houses.InsertOnSubmit(house);
+ Context.Context.SubmitChanges();
+ }
+ catch (Exception ex)
+ {
+ return HouseCreationStatus.GeneralError;
+ }
+
+ return HouseCreationStatus.Success;
+ }
+
+ /// <summary>
/// Returns the first house for a specific character GUID.
/// </summary>
/// <param name="GUID">A Guid instance for a character.</param>
@@ -61,4 +86,13 @@ public House GetForPosition(int X, int Y)
}
}
}
+
+ public enum HouseCreationStatus
+ {
+ NameAlreadyExisted,
+ NameTooLong,
+ ExceededHouseLimit,
+ Success,
+ GeneralError
+ }
}
@@ -66,7 +66,7 @@ public HouseAccess Houses
{
get
{
- if (_Character == null)
+ if (_House == null)
{
_House = new HouseAccess(this);
}
@@ -48,6 +48,7 @@ public enum PacketType
LOT_PURCHASE_FAILED = 0x80,
LOT_PURCHASE_OCCUPIED = 0x81,
LOT_UNBUILDABLE = 0x82,
- LOT_COST = 0x83
+ LOT_NAME_TOO_LONG = 0x83,
+ LOT_COST = 0x84
}
}
@@ -447,8 +447,26 @@ public static void HandleLotPurchaseRequest(NetworkClient Client, ProcessedPacke
if (Char.Money >= NetworkFacade.LOT_COST)
{
Char.HouseHouse = new House();
+ Char.HouseHouse.Name = "Yolo"; //TODO: Fixme
Char.HouseHouse.X = X;
Char.HouseHouse.Y = Y;
+
+ switch(db.Houses.CreateHouse(Char.HouseHouse))
+ {
+ case CityDataModel.Entities.HouseCreationStatus.GeneralError:
+ PacketStream UnbuildablePacket = new PacketStream((byte)PacketType.LOT_UNBUILDABLE, 0);
+ UnbuildablePacket.WriteByte(0x00);
+ Client.SendEncrypted((byte)PacketType.LOT_UNBUILDABLE, UnbuildablePacket.ToArray());
+ return;
+ case CityDataModel.Entities.HouseCreationStatus.NameTooLong:
+ PacketStream NameTooLongPacket = new PacketStream((byte)PacketType.LOT_NAME_TOO_LONG, 0);
+ NameTooLongPacket.WriteByte(0x00);
+ Client.SendEncrypted((byte)PacketType.LOT_NAME_TOO_LONG, NameTooLongPacket.ToArray());
+ return;
+ default:
+ break;
+ }
+
Char.Money -= NetworkFacade.LOT_COST;
PacketStream SuccessPacket = new PacketStream((byte)PacketType.LOT_PURCHASE_SUCCESSFUL, 0);
@@ -98,6 +98,7 @@ public override void Add(_3DComponent item)
private float m_ShadowMult = 1;
//private double m_DayNightCycle = 0.0;
private int[] m_SelTile = new int[] { -1, -1 };
+ private int[] m_SelTileTmp = new int[] { -1, -1 }; //For storing value of SelTile to use when clicking dialogs.
private Matrix m_MovMatrix;
private Texture2D m_WhiteLine;
private Texture2D m_stpWhiteLine;
@@ -1274,6 +1275,9 @@ public override void Update(UpdateState state)
{
if (m_SelTile[0] != -1 && m_SelTile[1] != -1)
{
+ m_SelTileTmp[0] = m_SelTile[0];
+ m_SelTileTmp[1] = m_SelTile[1];
+
UIAlertOptions AlertOptions = new UIAlertOptions();
AlertOptions.Title = GameFacade.Strings.GetString("246", "1");
AlertOptions.Message = GameFacade.Strings.GetString("215", "23", new string[]
@@ -1305,9 +1309,12 @@ public override void Update(UpdateState state)
}
}
+ /// <summary>
+ /// Player selected "yes" to buy a new lot.
+ /// </summary>
private void BuyPropertyAlert_OnButtonClick(UIElement Button)
{
- Network.UIPacketSenders.SendLotPurchaseRequest(Network.NetworkFacade.Client, (short)m_SelTile[0], (short)m_SelTile[1]);
+ Network.UIPacketSenders.SendLotPurchaseRequest(Network.NetworkFacade.Client, (short)m_SelTileTmp[0], (short)m_SelTileTmp[1]);
UIScreen.RemoveDialog(m_BuyPropertyAlert);
}
@@ -439,6 +439,9 @@ public void _OnLotUnbuildable(NetworkClient Client, ProcessedPacket Packet)
}
}
+ /// <summary>
+ /// Lot purchase was successful, server sent correct amount of money for player's character's account.
+ /// </summary>
public void _OnLotPurchaseSuccessful(NetworkClient Client, ProcessedPacket Packet)
{
int Money = UIPacketHandlers.OnLotPurchaseSuccessful(Client, Packet);
@@ -451,6 +454,11 @@ public void _OnLotPurchaseSuccessful(NetworkClient Client, ProcessedPacket Packe
}
}
+ public void _OnLotNameTooLong(NetworkClient Client, ProcessedPacket Packet)
+ {
+ //TODO: Handle this.
+ }
+
/// <summary>
/// Authenticate with the service client to get a token,
/// Then get info about avatars & cities
@@ -106,6 +106,7 @@ static NetworkFacade()
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));
+ PacketHandlers.Register((byte)PacketType.LOT_NAME_TOO_LONG, true, 0, new OnPacketReceive(Controller._OnLotNameTooLong));
}
}
}

0 comments on commit 85208f7

Please sign in to comment.