public void Update(int userId, IEnumerable <Team> teams)
        {
            var userAssociations = _appDbContext.TeamAssociations.Where(x => x.UserId == userId);

            foreach (var team in teams)
            {
                var association = userAssociations.FirstOrDefault(x => x.UserId == userId && x.TeamId == team.Id);

                if (association != null && !team.Selected)
                {
                    _appDbContext.TeamAssociations.Remove(association);
                    _appDbContext.Teams.First(t => t.Id == team.Id).UserCount -= 1;
                }
                else if (association == null && team.Selected)
                {
                    var date = DateTime.Now;
                    association = new TeamAssociation()
                    {
                        Created  = date,
                        Modified = date,
                        TeamId   = team.Id,
                        UserId   = userId
                    };
                    _appDbContext.TeamAssociations.Add(association);
                    _appDbContext.Teams.First(t => t.Id == team.Id).UserCount += 1;
                }
            }
            CommitChanges();
        }
        public void Remove(TeamAssociation entity, bool commit = true)
        {
            _appDbContext.TeamAssociations.Remove(entity);
            _appDbContext.Teams.First(t => t.Id == entity.TeamId).UserCount -= 1;

            if (commit)
            {
                CommitChanges();
            }
        }
Ejemplo n.º 3
0
    bool EngageInCombat(Map.EntityTypes entityType)
    {
        int layerMask = 0;

        switch (entityType)
        {
        case Map.EntityTypes.Minion:
            layerMask = 8;
            break;

        case Map.EntityTypes.Hero:
            layerMask = 10;
            break;

        case Map.EntityTypes.Building:
            layerMask = 11;
            break;

        default:
            Debug.LogWarningFormat(this, "Trying to engage into combat with {0} - no case for that available!", entityType);
            return(false);
        }

        RaycastHit[] hits = Physics.SphereCastAll(transform.position, 3f, transform.forward, 3f, 1 << layerMask);
        foreach (RaycastHit hit in hits)
        {
            TeamAssociation teamAssociation = hit.transform.GetComponent <TeamAssociation>();
            if (teamAssociation)
            {
                if (teamAssociation.IsLeftTeam != TeamAssociation.IsLeftTeam)
                {
                    if (hit.transform.GetComponent <DamageInterface>())
                    {
                        AttackBehaviour.CurrentEnemy = hit.transform.GetComponent <DamageInterface>();
                        CurrentlyAttackedType        = entityType;
                        return(true);
                    }
                }
            }
        }
        return(false);
    }
Ejemplo n.º 4
0
 public void Start()
 {
     AttackBehaviour = GetComponent <AttackBehaviour>();
     TeamAssociation = GetComponent <TeamAssociation>();
     NavMeshAgent    = GetComponent <NavMeshAgent>();
 }