コード例 #1
0
            public async Task OneDepartmentPermission_ReturnsForCompany()
            {
                int unitId       = 99;
                int departmentId = 88;
                int userId       = 1;

                A.CallTo(() => PermissionService.GetImplicitByUnitType(UnitType.Master)).Returns(new List <PermissionType> {
                    PermissionType.EndreKompetanseType
                });
                A.CallTo(() => AuthorizationQueries.GetUnitPermissionsByUserId(A <int> .Ignored, A <int?> .Ignored, A <PermissionType[]> .Ignored)).Returns(new List <UnitPermission> {
                    new UnitPermission {
                        UnitId = departmentId, PermissionType = PermissionType.LesNyheter
                    }
                });
                A.CallTo(() => UnitQueries.GetByIdList(A <IEnumerable <int> > .Ignored)).Returns(new List <UnitWithParent> {
                    new UnitWithParent {
                        Id = departmentId, ParentId = unitId, Type = UnitType.Department
                    }
                });
                A.CallTo(() => PermissionService.GetByUnitType(UnitType.Department)).Returns(new List <PermissionType>());
                A.CallTo(() => UnitQueries.GetHierarchyUp(departmentId)).Returns(new List <UnitWithParent> {
                    new UnitWithParent {
                        Id = unitId, ParentId = null, Type = UnitType.Company
                    }
                });

                var list = await AuthorizationService.GetUnitPermissions(userId, null, PermissionType.EndreKompetanseType);

                Assert.That(list != null && list.Count() == 2);
                Assert.That(list.First().PermissionType == PermissionType.EndreKompetanseType && list.First().UnitId == UnitConstants.MasterUnitId);
                Assert.That(list.Last().PermissionType == PermissionType.LesNyheter && list.Last().UnitId == unitId);
            }
コード例 #2
0
    public static void Mate(Unit unit) {
        GameObject closestMateObj = UnitQueries.ClosestMate(unit);
        if (closestMateObj == null) return;
        Unit closestMate = closestMateObj.GetComponent<Unit>();
        closestMate.horny = false;
        unit.horny = false;

        List<Unit> allies = GameManager.gameManager.petList;
        List<Unit> enemies = GameManager.gameManager.enemyList;
        if ( allies.Count + enemies.Count < GameManager.gameManager.maxUnits) {
            //todo: spawn in position of parents: force into orbit
            GameManager.gameManager.GetSpeciesFromName(unit.speciesName).Spawn();
        }
    }
コード例 #3
0
    public static void UpdateIsSwimming(Unit unit)
    {
        float minDistance = 1f;
        List<Vector3> vertices = UnitQueries.GetWaterVertices();
        foreach (var vertex in vertices)
        {
            if (Vector3.SqrMagnitude(unit.waterDetector.position - vertex) < minDistance)
            {
                unit.swimming = true;
                return;
            }
        }
        unit.swimming = false; //if no vertex is within distance

    }
コード例 #4
0
    //does the unit require to be given a new destination
    public static bool NeedsWanderingDestination(Unit unit)
    {
        //no destination
        if (unit.GetComponent <Target>().targetVector3 == Vector3.zero)
        {
            return(true);
        }

        ////destination already reached
        if (UnitQueries.IsNearTarget(unit))
        {
            return(true);
        }
        //if its wandering and couldn't reach the destination in 10 sec reset
        if (Time.time - unit.wanderTimeStamp > 3f && unit.unitState == UnitState.Wander)
        {
            return(true);
        }

        //otherwise
        return(false);
    }
コード例 #5
0
    public static UnitState NextState(Unit unit)   //returns next state
    //todo: if enemies approach them they start attacking? or only if the user puts them in attack mode
    //if they don't start attacking do they run away?

    //todo: only show mating thought when having a baby (make the f*****g process longer)
    //todo: add actions that happen from every state here!
    {
        if (unit.shouldDie)
        {
            UnitActions.Die(unit); return(UnitState.Dead);
        }

        switch (unit.unitState)
        {
        case UnitState.Wander: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            //rethink this
            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            if (UnitQueries.NeedsChange(unit))
            {
                return(UnitState.TargetBase);
            }                                                                           //TODO this should probably override everything cause it seems like a bug otherwise
            if (UnitQueries.IsHungry(unit) && UnitQueries.FoodSourceAvailable(unit))
            {
                UnitActions.TargetFood(unit); return(UnitState.TargetFood);
            }
            if (UnitQueries.IsThirsty(unit))
            {
                UnitActions.TargetWater(unit); return(UnitState.TargetWater);
            }
            if (UnitQueries.IsHorny(unit) && UnitQueries.AvailableMate(unit))
            {
                return(UnitState.TargetMate);
            }
            if (UnitQueries.GenetiumAvailable(unit) && !UnitQueries.IsStorageFull(unit))           //todo: make funuction is genetium available? (unit storage not full, genetium enough genetium, genetium chosen in species)
            {
                UnitActions.TargetGenetium(unit); return(UnitState.TargetGenetium);
            }
            if (UnitQueries.IsCarryingGenetium(unit))
            {
                return(UnitState.TargetBase);
            }
            UnitActions.Wander(unit);
            break;
        }

        case UnitState.TargetWater: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            //if (!UnitQueries.SeesWater(unit)) { return UnitState.Wander; }
            if (UnitQueries.IsNearTarget(unit))
            {
                return(UnitState.Drink);
            }

            break;
        }

        case UnitState.TargetFood: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            //todo handle change of food source as its targetting
            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            //if (!UnitQueries.SeesFood(unit)) { return UnitState.Wander; }
            if (UnitQueries.IsNearTarget(unit))
            {
                return(UnitState.Eat);
            }
            break;
        }

        case UnitState.TargetMate: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            UnitActions.TargetMate(unit);
            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            if (!UnitQueries.AvailableMate(unit))
            {
                return(UnitState.Wander);
            }
            if (UnitQueries.IsNearTarget(unit))
            {
                return(UnitState.Mate);
            }
            break;
        }

        case UnitState.TargetGenetium: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            //if (UnitQueries.IsThreatened(unit)) { return UnitState.Wander; }
            if (UnitQueries.IsHungry(unit) && UnitQueries.FoodSourceAvailable(unit))
            {
                UnitActions.TargetFood(unit); return(UnitState.TargetFood);
            }
            if (UnitQueries.IsThirsty(unit))
            {
                UnitActions.TargetWater(unit); return(UnitState.TargetWater);
            }
            //todo handle change of genetium source as its targetting
            if (UnitQueries.IsNearTarget(unit))
            {
                return(UnitState.Harvest);
            }

            break;
        }

        case UnitState.TargetBase: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            UnitActions.TargetBase(unit);
            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            if (UnitQueries.IsHungry(unit) && UnitQueries.FoodSourceAvailable(unit))
            {
                UnitActions.TargetFood(unit); return(UnitState.TargetFood);
            }
            if (UnitQueries.IsThirsty(unit))
            {
                UnitActions.TargetWater(unit); return(UnitState.TargetWater);
            }
            if (UnitQueries.IsNearTarget(unit))
            {
                UnitActions.ReachBase(unit); return(UnitState.Wander);
            }
            break;
        }

        case UnitState.TargetEnemy: {
            UnitActions.TargetEnemy(unit);
            //if (UnitQueries.HasLowHealth(unit)) { return UnitState.Flee; }
            //if (UnitQueries.IsVeryHungry(unit)) { return UnitState.Flee; }
            //if (UnitQueries.IsVeryThirsty(unit)) { return UnitState.Flee; }
            if (UnitQueries.IsNearTarget(unit))
            {
                return(UnitState.Attack);
            }
            if (!UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.Wander);
            }
            break;
        }

        //todo: change food and genetium to be near the known food target
        case UnitState.Drink: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            if (UnitQueries.IsQuenched(unit))
            {
                UnitActions.TurnQuenched(unit); return(UnitState.Wander);
            }
            UnitActions.Drink(unit);
            break;
        }

        case UnitState.Eat: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            //todo handle change of food source as its eating
            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            if (UnitQueries.IsFed(unit))
            {
                UnitActions.TurnFed(unit); return(UnitState.Wander);
            }
            UnitActions.Eat(unit);
            break;
        }

        case UnitState.Mate: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            if (!UnitQueries.IsHorny(unit))
            {
                return(UnitState.Wander);
            }
            UnitActions.Mate(unit);
            break;
        }

        case UnitState.Harvest: {
            if (unit.isBeingOverride)
            {
                return(UnitState.Override);
            }

            //todo handle change of genetium source as its harvesting
            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }
            if (!UnitQueries.IsNearTarget(unit))
            {
                return(UnitState.Wander);
            }
            if (UnitQueries.IsStorageFull(unit))
            {
                return(UnitState.Wander);
            }
            if (!UnitQueries.GenetiumAvailable(unit))
            {
                return(UnitState.Wander);
            }
            UnitActions.Harvest(unit);
            break;
        }

        case UnitState.Attack: {
            //if (unit.isBeingOverride) return UnitState.Override;

            if (UnitQueries.IsTargettedEnemyDead(unit))
            {
                return(UnitState.Wander);
            }
            if (!UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.Wander);
            }
            //if (UnitQueries.HasLowHealth(unit)) { return UnitState.Flee; }

            if (!UnitQueries.IsNearTarget(unit))
            {
                return(UnitState.TargetEnemy);
            }

            UnitActions.Attack(unit);
            break;
        }

        case UnitState.Flee: {
            UnitActions.Flee(unit);
            if (!UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.Wander);
            }
            break;
        }

        case UnitState.Override: {
            //todo: think how override behaves with enemies in range
            if (UnitQueries.IsNearTarget(unit))
            {
                UnitActions.StopOverride(unit); return(UnitState.Wander);
            }
            if (UnitQueries.EnemyInRange(unit))
            {
                return(UnitState.TargetEnemy);
            }

            break;
        }
        }

        return(unit.unitState); //no state change
    }
コード例 #6
0
 public static void TargetMate(Unit unit) {
     GameObject closestMate = UnitQueries.ClosestMate(unit);
     if (closestMate == null) return;
     unit.GetComponent<Target>().Change(closestMate, closestMate.GetComponent<Unit>().matingDistance);
 }
コード例 #7
0
 public static void TargetWater(Unit unit) {
     Vector3 closestWaterPoint = UnitQueries.ClosestWater(unit);
     unit.GetComponent<Target>().Change(closestWaterPoint);
 }
コード例 #8
0
 public static void Wander(Unit unit) {
     if (UnitQueries.NeedsWanderingDestination(unit)) {
         UnitActions.SetWanderingDestination(unit);
     }
 }
コード例 #9
0
 public static void Flee(Unit unit) {
     GameObject closestEnemy = UnitQueries.ClosestEnemyInRange(unit);
     if (closestEnemy == null || closestEnemy.GetComponent<Unit>() == null) return;
     SetFleeingTarget(unit, closestEnemy.GetComponent<Unit>());
 }
コード例 #10
0
 public static void TargetEnemy(Unit unit) {
     GameObject closestEnemy = UnitQueries.ClosestEnemyInRange(unit);
     if (closestEnemy == null || closestEnemy.GetComponent<Unit>() == null) return;
     unit.GetComponent<Target>().Change(closestEnemy, closestEnemy.GetComponent<Unit>().interactionRadius);
 }
コード例 #11
0
    public static bool SeesWater(Unit unit)
    {
        Vector3 closestWaterSource = UnitQueries.ClosestWater(unit);

        return(closestWaterSource != Vector3.zero);
    }