Esempio n. 1
0
 public FindDivision(DivisionController controller, DivisionController commanderSendingOrder, RememberedDivision finish)
 {
     this.commanderSendingOrder = commanderSendingOrder;
     this.controller            = controller;
     this.finish = finish;
     this.target = null;
 }
Esempio n. 2
0
    /// <summary>
    /// used when copying
    /// </summary>
    /// <param name="division"></param>
    /// <param name="controller"></param>
    public Division(Division division, DivisionController controller = null)
    {
        this.Commander = division.Commander;

        this.PossibleOrders = new List <Order>(division.PossibleOrders);
        this.Subordinates   = new HashSet <int>(division.Subordinates);

        this.Soldiers    = new ObservableCollection <Soldier>(division.Soldiers);
        this.NumSoldiers = division.NumSoldiers;
        if (division.CommandingOfficer != null)
        {
            this.CommandingOfficer = new Officer(division.CommandingOfficer);
        }

        this.DivisionId = division.DivisionId;
        this.TeamId     = division.TeamId;

        OrderSystem = new MultiOrder(this, DivisionId, "division order queues", new List <Order>(), false);
        this.OrderSystem.OngoingOrder = division.OrderSystem.OngoingOrder;

        this.Name       = "Division " + DivisionId;
        this.Controller = controller;

        this.Zones       = division.Zones;
        this.IsMessenger = division.IsMessenger;

        SetupModifiers();
        RecalculateAggrigateValues();
        this.Soldiers.CollectionChanged += OnSoldiersChanged;
    }
Esempio n. 3
0
    public override void Proceed()
    {
        Vector3 currLoc          = controller.transform.position;
        float   distanceToFinish = (finish.position - currLoc).magnitude;

        //if target is null look for it in the visible divisions
        if (target == null)
        {
            controller.FindVisibleDivision(finish.divisionId, out target);
        }

        //if it isnt null go find em
        if (target != null)
        {
            distanceToFinish = (target.transform.position - currLoc).magnitude;
        }

        //when this is true then we have caught up to our target
        if (distanceToFinish < .1f && !hasFoundTarget)
        {
            hasFoundTarget = true;
            target         = null;
        }

        moveToTarget();
    }
Esempio n. 4
0
 public void AddDivision(DivisionController division)
 {
     if (!Divisions.Contains(division))
     {
         Divisions.Add(division);
     }
 }
Esempio n. 5
0
 public void DivisionTestSetUp()
 {
     _service = new List <DivisionService>()
     {
         new DivisionService()
     };
     _controller = new DivisionController(_service);
 }
Esempio n. 6
0
 public SendMessage(DivisionController controller, DivisionController commanderSendingOrder, List <Order> message, RememberedDivision target)
 {
     this.commanderSendingOrder = commanderSendingOrder;
     this.controller            = controller;
     this.finish  = target;
     this.target  = null;
     this.message = message;
 }
Esempio n. 7
0
    private void OnDivisionExitSight(DivisionController controller)
    {
        //Debug.Log($"exit {this.name} {controller.name}");
        //VisibleControllers.ForEach(x => x.RefreshVisibleDivisions());
        RefreshVisibleDivisions();

        VisibleControllers.Remove(controller);
        //VisibleControllers.ForEach(x => x.RefreshVisibleDivisions());
    }
Esempio n. 8
0
    public void Init(DivisionController controller = null)
    {
        this.DivisionId = DivisionCounter;
        DivisionCounter++;

        this.Name        = "Division " + DivisionId;
        this.Controller  = controller;
        this.OrderSystem = new MultiOrder(this, DivisionId, "division order queues", new List <Order>(), false);
        this.OrderSystem.OngoingOrder = new EmptyOrder();
    }
Esempio n. 9
0
    public void SendMessenger(RememberedDivision to, RememberedDivision endTarget, List <Order> orders)
    {
        //create a new division
        DivisionController messenger = CreateNewDivision((int)CommandingOfficer.MessengerDivisionSoldierCnt.Value);

        messenger.AttachedDivision.IsMessenger = true;
        messenger.name = "messenger";
        messenger.AttachedDivision.ReceiveOrder(new FindDivision(messenger.AttachedDivision, DivisionId, to.DivisionId));
        messenger.AttachedDivision.ReceiveOrder(new SendMessage(messenger.AttachedDivision, DivisionId, orders, to.DivisionId, endTarget.DivisionId));
    }
 public AIControlledDivision(int teamId = -1, DivisionController controller = null, bool enableAI = true)
     : base(teamId, controller)
 {
     _enableAI = enableAI;
     if (_enableAI)
     {
         //ReceiveOrder(new AIOrder(this, DivisionId));
         OrderSystem = new AIOrder(this, DivisionId);
         this.OrderSystem.OngoingOrder = new EmptyOrder();
     }
 }
Esempio n. 11
0
    public void Setup(DivisionController division)
    {
        this.division = division;

        //build menu
        Dictionary <SoldierType, List <Soldier> > soldiersSplitIntoTypes =
            division.SplitSoldiersIntoTypes();

        foreach (var soldierGroup in soldiersSplitIntoTypes)
        {
            CreateCard(soldierGroup.Key, soldierGroup.Value);
        }
    }
Esempio n. 12
0
    public virtual DivisionController CreateChild(List <Soldier> soldiersForChild)
    {
        GameObject         newDivision   = Instantiate(divisonPrefab);
        DivisionController newController = newDivision.GetComponent <DivisionController>();

        newController.Init(GenerateRememberedDivision());
        newController.soldiers         = soldiersForChild;
        newDivision.transform.position = this.transform.position;
        newDivision.transform.rotation = this.transform.rotation;
        subordinates.Add(newController.GenerateRememberedDivision());
        GameManager.instance.RefreshAllDivisons();
        return(newController);
    }
Esempio n. 13
0
    public void AbsorbDivision(DivisionController other)
    {
        TransferSoldiers(other.soldiers);
        //kick him out of his commanders subordinate list
        RememberedDivision parent = other.commander;

        if (parent != null)
        {
            parent.RemoveSubordinate(other.GenerateRememberedDivision());
        }
        GameObject.Destroy(other.gameObject);
        GameManager.instance.RefreshAllDivisons();
    }
Esempio n. 14
0
 public void select(DivisionController divisionController)
 {
     if (!UIwaitingForSelection)
     {
         selected = divisionController;
         //bing up order ui
         OrderDisplayManager.instance.ClearOrders();
         OrderDisplayManager.instance.AddOrderSet(selected.possibleOrders);
     }
     else
     {
         UIResponse(divisionController);
     }
 }
Esempio n. 15
0
    //use for creating a new division from inside a new controller
    public Division(int teamId, DivisionController controller = null)
    {
        this.Commander = -1;

        this.PossibleOrders = new List <Order>();
        this.Subordinates   = new HashSet <int>();
        this.Soldiers       = new ObservableCollection <Soldier>();

        Init(controller);
        this.Soldiers.CollectionChanged += OnSoldiersChanged;

        this.TeamId = teamId;
        SetupModifiers();
    }
Esempio n. 16
0
    private void OnDivisionEnterSight(DivisionController controller)
    {
        //Debug.Log($"enter {this.name} {controller.name}");

        if (VisibleControllers.Contains(controller))
        {
            VisibleControllers.Remove(controller);
        }

        VisibleControllers.Add(controller);

        //VisibleControllers.ForEach(x => x.RefreshVisibleDivisions());
        RefreshVisibleDivisions();
        //VisibleControllers.ForEach(x => x.RefreshVisibleDivisions());
    }
Esempio n. 17
0
        public void TestSelectPost_NoSelection()
        {
            IRpcBroker broker = MockRpcBrokerFactory.GetXusDivisionSetBroker(true);

            DivisionController controller = new DivisionController(broker);

            FormCollection formCollection = new FormCollection();

            ActionResult result = controller.Select(formCollection);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            RedirectToRouteResult routeResult = (RedirectToRouteResult)result;

            Assert.AreEqual("Select", routeResult.RouteValues["action"]);
        }
Esempio n. 18
0
    public DivisionController CreateChild(List <Soldier> soldiersForChild)
    {
        GameObject         newDivision   = Instantiate(DivisionControllerManager.Instance.DivisionPrefab);
        DivisionController newController = newDivision.GetComponent <DivisionController>();

        newController.transform.position      = transform.position;
        newController.Controller              = Controller;
        newController.AttachedDivision.TeamId = Controller.TeamId;
        newController.AttachedDivision.Soldiers.Clear();
        newController.AttachedDivision.TransferSoldiers(soldiersForChild);
        newController.AttachedDivision.PromoteOfficer();
        newController.AttachedDivision.Commander = AttachedDivision.DivisionId;
        AttachedDivision.AddSubordinate(new RememberedDivision(newController.AttachedDivision));
        DivisionControllerManager.Instance.AddDivision(newController);

        return(newController);
    }
Esempio n. 19
0
    public virtual Division CreateChild(List <Soldier> soldiersForChild, DivisionController newController)
    {
        newController.transform.position = this.Controller.transform.position;
        newController.transform.rotation = this.Controller.transform.rotation;

        ControlledDivision newDivision = new ControlledDivision(TeamId, newController)
        {
            Soldiers = new ObservableCollection <Soldier>(soldiersForChild)
        };

        AddSubordinate(new RememberedDivision(newDivision));
        newDivision.Commander = DivisionId;
        OnChange();
        newDivision.OnChange();
        newController.AttachedDivision = newDivision;
        return(newDivision);
    }
Esempio n. 20
0
        public void TestPutDivisionNotFound()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    var division = new Division {
                        DivisionCode = 1
                    };
                    context.Division.Add(division);
                    context.Division.Add(new Division {
                        DivisionCode = 2
                    });
                    context.Division.Add(new Division {
                        DivisionCode = 3
                    });
                    context.SaveChanges();

                    DivisionController controller = new DivisionController(context);
                    division.DivisionId   = 4;
                    division.DivisionName = "division4";
                    division.DivisionCode = 4;

                    var actionResult = controller.PutDivision(division.DivisionId, division.ToDivisionV1DTO()).Result;
                    var result       = actionResult as NotFoundResult;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(404, result.StatusCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 21
0
        public void TestGetDivision()
        {
            var connection = new SqliteConnection("Datasource=:memory:");

            connection.Open();

            try
            {
                var options = new DbContextOptionsBuilder <InternalServicesDirectoryV1Context>()
                              .UseSqlite(connection)
                              .Options;

                // test a successful case
                using (var context = new InternalServicesDirectoryV1Context(options))
                {
                    context.Database.EnsureCreated();
                    context.Division.Add(new Division {
                        DivisionCode = 1
                    });
                    context.Division.Add(new Division {
                        DivisionCode = 2
                    });
                    context.Division.Add(new Division {
                        DivisionCode = 3
                    });
                    context.SaveChanges();

                    DivisionController controller = new DivisionController(context);
                    var actionResult = controller.Get(2).Result;
                    var result       = actionResult as OkObjectResult;
                    var division     = result.Value as DivisionV1DTO;

                    Assert.IsNotNull(result);
                    Assert.AreEqual(200, result.StatusCode);
                    Assert.IsNotNull(division);
                    Assert.AreEqual(2, division.DivisionId);
                    Assert.AreEqual(2, division.DivisionCode);
                }
            }
            finally
            {
                connection.Close();
            }
        }
Esempio n. 22
0
    public void SendMessenger(RememberedDivision to, Order order)
    {
        //create a new division
        //todo make the messenger descesion smart
        List <Soldier> soldiersToGive = new List <Soldier>();

        soldiersToGive.Add(PopSoldier());
        DivisionController messenger = CreateChild(soldiersToGive);

        //give it a move order to go to the division
        List <Order> orders = new List <Order>();

        orders.Add(order);
        //todo discover location of to
        messenger.ReceiveOrder(new FindDivision(messenger, this, to));
        messenger.ReceiveOrder(new SendMessage(messenger, this, orders, to));
        //messenger.ReceiveOrder(new FindDivision(messenger, this, messenger));
        // messenger.ReceiveOrder
    }
Esempio n. 23
0
    public bool TryCreateNewDivision(out DivisionController newDivision)
    {
        Soldier soldier = null;

        try
        {
            soldier = PopSoldier();
        }
        catch (InsufficientSoldierCountException)
        {
            newDivision = null;
            return(false);
        }

        List <Soldier> soldiersToGive = new List <Soldier>
        {
            soldier
        };

        newDivision = Controller.CreateChild(soldiersToGive);
        return(true);
    }
Esempio n. 24
0
    public void RenderMapWithTilesAndVision(DivisionController controller, Color visionColor)
    {
        int sightDistance = Mathf.RoundToInt(controller.AttachedDivision.MaxSightDistance);

        if (controller == null)
        {
            return;
        }

        Vector2    controllerPosition        = controller.transform.position;
        Vector2Int controllerPositionRounded = new Vector2Int(RoundVector(controller.transform.position).x, RoundVector(controller.transform.position).y);

        //for the x and ys we go one over so that we erase the old sight tiles as we walk past them
        for (int x = -sightDistance - 1; x <= sightDistance + 1; x++)
        {
            for (int y = -sightDistance - 1; y <= sightDistance + 1; y++)
            {
                var position = new Vector2Int(x, y) + controllerPositionRounded;
                var inVision = (new Vector2(position.x, position.y) - controllerPosition).magnitude < controller.AttachedDivision.MaxSightDistance;
                var color    = NotDiscovered;

                if (inVision)
                {
                    color = visionColor;
                }
                else if (InBounds(controller.AttachedDivision.discoveredMapLocations, position.x, position.y) && controller.AttachedDivision.discoveredMapLocations[position.x, position.y])
                {
                    color = FowGrey;
                }

                //TerrainTilemap.SetTileFlags(position, TileFlags.None);
                //TerrainTilemap.SetColor(position, color);

                SetTileColor(position, color);
            }
        }
    }
Esempio n. 25
0
    private void Update()
    {
        for (int i = 0; i < Divisions.Count; i++)
        {
            DivisionController division = Divisions[i];
            UnityEngine.Profiling.Profiler.BeginSample("find visible");
            division.FindVisibleDivisions();
            UnityEngine.Profiling.Profiler.EndSample();

            UnityEngine.Profiling.Profiler.BeginSample("do orders");
            division.AttachedDivision.OrderSystem.DoOrders(division.AttachedDivision);
            UnityEngine.Profiling.Profiler.EndSample();

            UnityEngine.Profiling.Profiler.BeginSample("do background orders");
            division.AttachedDivision.OrderSystem.DoBackgroundOrders(division.AttachedDivision);
            UnityEngine.Profiling.Profiler.EndSample();

            UnityEngine.Profiling.Profiler.BeginSample("check refresh");
            division.AttachedDivision.CheckRefresh();
            UnityEngine.Profiling.Profiler.EndSample();

            UnityEngine.Profiling.Profiler.BeginSample("on tick");
            division.OnTick();
            UnityEngine.Profiling.Profiler.EndSample();
        }

        for (int i = 0; i < Divisions.Count; i++)
        {
            DivisionController division = Divisions[i];
            if (division.AttachedDivision.HasBeenDestroyed)
            {
                Divisions.RemoveAt(i);
                i--;
            }
        }
    }
Esempio n. 26
0
 public bool FindVisibleDivision(int divisionID, out DivisionController division)
 {
     division = null;
     return(visibleDivisions.TryGetValue(divisionID, out division));
 }
Esempio n. 27
0
 public DivisionApiTest()
 {
     _seed       = Guid.NewGuid().ToString();
     _controller = MockController.CreateApi <DivisionController>(new DataContext(_seed, DBTypeEnum.Memory), "user");
 }
 public void Select(DivisionController divisionController)
 {
     Select(divisionController.AttachedDivision);
 }
Esempio n. 29
0
 public MergeDivisions(DivisionController controller, RememberedDivision target)
 {
     this.controller      = controller;
     this.target          = target;
     this.finishedMerging = false;
 }
Esempio n. 30
0
 void Start()
 {
     playerDivision = GameManager.instance.localPlayer.generalDivision;
 }