Exemplo n.º 1
0
    private static void AddRemoveUnits(AreaSyncData data)
    {
        List <string> wasRemoved, wasAdded;

        GetIds(data, out wasRemoved, out wasAdded);
        RemoveUnits(data, wasRemoved);
        AddUnits(data, wasAdded);
    }
Exemplo n.º 2
0
 private static void SyncMonsters(AreaSyncData data)
 {
     foreach (var monster in data.Monsters)
     {
         var unit = Object.Units.Find(x => x.combatData.UnitId == monster.CombatData.UnitId);
         if (unit != null)
         {
             unit.SyncCombatData(monster.CombatData);
         }
     }
 }
Exemplo n.º 3
0
 private static void SyncCharacters(AreaSyncData data)
 {
     foreach (var charater in data.Characters)
     {
         var unit = Object.Units.Find(x => x.combatData.UnitId == charater.CombatData.UnitId);
         if (unit != null)
         {
             unit.SyncCombatData(charater.CombatData);
         }
     }
 }
Exemplo n.º 4
0
 private static void RemoveUnits(AreaSyncData data, List <string> ids)
 {
     foreach (var id in ids)
     {
         var unit = Object.Units.Find(x => x.combatData.UnitId == id);
         if (unit != null)
         {
             Destroy(unit.gameObject);
         }
     }
 }
Exemplo n.º 5
0
    private static void GetIds(AreaSyncData data, out List <string> wasRemoved, out List <string> wasAdded)
    {
        List <string> previousIds = Object.previousData.Characters.Select(x => x.Id).ToList();

        previousIds.AddRange(Object.previousData.Monsters.Select(x => x.Id).ToList());
        List <string> currentIds = data.Characters.Select(x => x.Id).ToList();

        currentIds.AddRange(data.Monsters.Select(x => x.Id));

        wasRemoved = previousIds.Except(currentIds).ToList();
        wasAdded   = currentIds.Except(previousIds).ToList();
    }
Exemplo n.º 6
0
    private static void AddUnits(AreaSyncData data, List <string> ids)
    {
        foreach (var id in ids)
        {
            GameObject go = Instantiate(Object.unitPrefab, Object.unitContainer, false);

            var character = data.Characters.Find(x => x.CombatData.UnitId == id).CombatData;
            var monster   = data.Monsters.Find(x => x.CombatData.UnitId == id).CombatData;

            if (character != null)
            {
                go.GetComponent <Unit>().SyncCombatData(character);
            }
            else if (monster != null)
            {
                go.GetComponent <Unit>().SyncCombatData(monster);
            }
        }
    }
Exemplo n.º 7
0
 public void BroadcastAreaSync(AreaSyncData data)
 {
     logService.Log($"Broadcasting Area sync to clients on group: {data.Area.Id}");
     hubContext.Clients.Group(data.Area.Id).OnAreaSync(data);
 }
Exemplo n.º 8
0
 private static void SyncBattleground(AreaSyncData data)
 {
     AddRemoveUnits(data);
     SyncCharacters(data);
     SyncMonsters(data);
 }
Exemplo n.º 9
0
    public static void SyncArea(AreaSyncData data)
    {
        UIEvents.ChangeGameText(GameTextId.AreaName, data.Area.Name);

        SyncBattleground(data);
    }