Skip to content

Commit

Permalink
#6: Update with basic inventory/store UI to support local server mode…
Browse files Browse the repository at this point in the history
…. Still need to hook up inventory system for network sync within InventoryManager system
  • Loading branch information
Danil Ko committed Mar 1, 2021
1 parent 484129e commit a19ad61
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 25 deletions.
4 changes: 2 additions & 2 deletions agents/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public bool EquipWeapon(PackedScene weaponScene, Weapon.WeaponOrder weaponOrder,

// Set an incremental to current index, so weapon can be switched
int oldIndex = CurrentWeaponIndex[weaponOrder];
CurrentWeaponIndex[weaponOrder] = CurrentWeaponIndex[weaponOrder] + 1 % weapons.Count;
CurrentWeaponIndex[weaponOrder] = (CurrentWeaponIndex[weaponOrder] + 1) % weapons.Count;
changeWeapon(oldIndex, weaponOrder);

return true;
Expand Down Expand Up @@ -401,7 +401,7 @@ public void Fire(Weapon.WeaponOrder weaponOrder, int weaponAction)
// knock back effect
if (weapon.Fire(target) && MaxSpeed != 0)
{
Vector2 dir = (new Vector2(1, 0)).Rotated(GlobalRotation);
Vector2 dir = (new Vector2(1, 0)).Rotated(GlobalRotation);
MoveAndSlide(dir * -10 * weapon.KnockbackForce);
}
}
Expand Down
4 changes: 2 additions & 2 deletions agents/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void serverGetPlayerInput(String inputData)
}
}

public void SetHUD(HUD hud)
public void SetHUD(HUD hud, InventoryManager _inventoryManager)
{
_hud = hud;

Expand Down Expand Up @@ -76,7 +76,7 @@ public void SetHUD(HUD hud)

// Setup Inventory UI
_inventoryUI = (InventoryUI)_hud.GetNode("controlGame/InventoryUI");
_inventoryUI.Initialize(_gameWorld.GetInventoryManager(), CurrentInventory);
_inventoryUI.Initialize(_inventoryManager, CurrentInventory);
}

protected override void DisconnectWeapon(Weapon currentWeapon, Weapon.WeaponOrder weaponOrder)
Expand Down
16 changes: 14 additions & 2 deletions ai/TeamMapAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public bool isNewUnitAllow()
return true;
}

public void Initialize(GameWorld gameWorld, Godot.Collections.Array bases, Team.TeamCode team, PathFinding pathFinding)
public void Initialize(GameWorld gameWorld, InventoryManager inventoryManager, Godot.Collections.Array bases, Team.TeamCode team, PathFinding pathFinding)
{
_inventoryManager = gameWorld.GetInventoryManager();
_inventoryManager = inventoryManager;
_bases = bases;
_team.CurrentTeamCode = team;
_gameWorld = gameWorld;
Expand Down Expand Up @@ -232,9 +232,21 @@ public Agent CreateUnit(String unitName, String displayName, Boolean enableAI)

ChargeAmount(_unitCost);

_assignDefaultWeapon(unit);

return unit;
}

private void _assignDefaultWeapon(Agent agent)
{
// Add default wepaons
_inventoryManager.AddItem(_inventoryManager.GetPurchasableItemByID("SYC-600"), agent.GetInventory());
_inventoryManager.AddItem(_inventoryManager.GetPurchasableItemByID("SYC-800"), agent.GetInventory());
// TODO: There is bug with shield that will push agent back
// _inventoryManager.EquipItem(agent.GetInventory(), agent.GetInventory().GetItemIndex("SYC-600"), Weapon.WeaponOrder.Left, 0);
_inventoryManager.EquipItem(agent.GetInventory(), agent.GetInventory().GetItemIndex("SYC-800"), Weapon.WeaponOrder.Right, 0);
}

public void RemoveUnit(String unitID)
{
Agent agent = GetUnit(unitID);
Expand Down
19 changes: 9 additions & 10 deletions inventory/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,26 @@ public ItemResource GetItem(int index)
return _items[index];
}

public Boolean HasItem(ItemResource itemResource)
public int GetItemIndex(String itemID)
{
int foundIndex = -1;
if (_items.Count > 0)
{
int foundIndex = -1;

for (int index = 0; index < _items.Count; index++)
{
if (itemResource.ItemID == _items[index].ItemID)
if (_items[index] != null && itemID == _items[index].ItemID)
{
foundIndex = index;
}
}

if (foundIndex != -1)
{
return true;
}
}

return false;
return foundIndex;
}

public Boolean HasItem(ItemResource itemResource)
{
return GetItemIndex(itemResource.ItemID) != -1;
}

public bool RemoveItem(ItemResource itemResource)
Expand Down
10 changes: 3 additions & 7 deletions map/GameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ public override void _Ready()
random = new RandomNumberGenerator();
gameStates = (GameStates)GetNode("/root/GAMESTATES");

_initializeInventoryManager();
_initializeHUD();
_initializeCamera();
_initializeTileMap();
_initializeObsctacleManager();
_initializeCapaturableBaseManager();
_initializeInventoryManager();
_initializeTeamMapAI();


Expand Down Expand Up @@ -264,7 +264,7 @@ private void _initializeTeamMapAI()
ai.Name = nameof(TeamMapAI) + "_" + (Team.TeamCode)index;
AddChild(ai);

ai.Initialize(this, _capaturableBaseManager.GetBases(), (Team.TeamCode)index, _pathFinding);
ai.Initialize(this, _inventoryManager, _capaturableBaseManager.GetBases(), (Team.TeamCode)index, _pathFinding);

_teamMapAIs.Add(ai);

Expand All @@ -279,10 +279,6 @@ private void _initializeInventoryManager()
{
_inventoryManager = (InventoryManager)GetNode("InventoryManager");
}
public InventoryManager GetInventoryManager()
{
return _inventoryManager;
}

// Cacluate network rate base on send bytes, received snapshots, applied snapshots
private void _onNetworkRateTimerUpdate()
Expand Down Expand Up @@ -1231,7 +1227,7 @@ private void _cratePlayer(int netId, Team.TeamCode team, String unitName, String
if (netId == network.gamestateNetworkPlayer.net_id)
{
// Attach camera
agent.SetHUD(_hud);
agent.SetHUD(_hud, _inventoryManager);
agent.SetCameraRemotePath(_camera2D);

// Set player marker
Expand Down
4 changes: 2 additions & 2 deletions map/SimulateGameWorld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public override void _Ready()
random = new RandomNumberGenerator();
gameStates = (GameStates)GetNode("/root/GAMESTATES");

_initializeInventoryManager();
_initializeCamera();
_initializeTileMap();
_initializeCapaturableBaseManager();
_initializeInventoryManager();
_initializeTeamMapAI();
_syncBots();

Expand Down Expand Up @@ -137,7 +137,7 @@ private void _initializeTeamMapAI()
ai.Name = nameof(TeamMapAI) + "_" + (Team.TeamCode)index;
AddChild(ai);

ai.Initialize(this, _capaturableBaseManager.GetBases(), (Team.TeamCode)index, _pathFinding);
ai.Initialize(this, _inventoryManager, _capaturableBaseManager.GetBases(), (Team.TeamCode)index, _pathFinding);

_teamMapAIs.Add(ai);

Expand Down

0 comments on commit a19ad61

Please sign in to comment.