コード例 #1
0
        private void PopulateUnitList()
        {
            foreach (var unitTemplate in AvailableTemplates)
            {
                var cachedUnitTemplate = unitTemplate;

                var newRecord = Instantiate(UnitRecordPrefab);

                newRecord.gameObject.SetActive(true);
                newRecord.transform.SetParent(UnitRecordContainer, false);

                newRecord.GetComponentInChildren <Text>().text = unitTemplate.name;

                var recordToggle = newRecord.GetComponentInChildren <Toggle>();

                recordToggle.onValueChanged.AddListener(delegate(bool isOn) {
                    if (isOn)
                    {
                        ActiveTemplate = cachedUnitTemplate;
                    }
                });

                if (recordToggle.isOn)
                {
                    ActiveTemplate = unitTemplate;
                }
                else if (ActiveTemplate == unitTemplate)
                {
                    recordToggle.isOn = true;
                }

                InstantiatedRecords.Add(newRecord);
            }
        }
コード例 #2
0
        public bool CanBuildUnit(IHexCell location, IUnitTemplate template, ICivilization owner)
        {
            var canPlace        = UnitPositionCanon.CanPlaceUnitTemplateAtLocation(template, location, owner);
            var hasForeignUnits = DoesCellHaveUnitsForeignTo(location, owner);;

            return(canPlace && !hasForeignUnits);
        }
コード例 #3
0
 public int GetIndex(IUnitTemplate unitTemplate)
 {
     if (unitsAvailable == null)
     {
         MakeDictionnary();
     }
     return(unitsAvailable[unitTemplate]);
 }
コード例 #4
0
        private IProductionProject BuildProject(IUnitTemplate unitTemplate)
        {
            var mockProject = new Mock <IProductionProject>();

            mockProject.Setup(project => project.UnitToConstruct).Returns(unitTemplate);

            return(mockProject.Object);
        }
コード例 #5
0
 /// <inheritdoc/>
 public IProductionProject ConstructProject(IUnitTemplate template)
 {
     return(new ProductionProject(
                template, UnitFactory, CityPossessionCanon,
                CityLocationCanon, StartingExperienceLogic,
                LocalPromotionLogic
                ));
 }
コード例 #6
0
 public MockUnitInfoTemplateBuilder()
 {
     _unitInfo = Substitute.For <IUnitTemplate>();
     _unitInfo.competenceTemplates.Returns(new List <ICompetenceTemplate>());
     _unitInfo.displacement.Returns(Random.Range(0.0f, 100.0f));
     _unitInfo.maxLife.Returns(Random.Range(0, 100));
     _unitInfo.name.Returns(Util.GetRandomString());
 }
コード例 #7
0
        private IUnit BuildUnit(IUnitTemplate template)
        {
            var mockUnit = new Mock <IUnit>();

            mockUnit.Setup(unit => unit.Template).Returns(template);

            return(mockUnit.Object);
        }
コード例 #8
0
 private ProductionProject BuildProductionProject(IUnitTemplate unitToConstruct)
 {
     return(new ProductionProject(
                unitToConstruct, MockUnitFactory.Object, MockCityPossessionCanon.Object,
                MockCityLocationCanon.Object, MockStartingExperienceLogic.Object,
                MockLocalPromotionLogic.Object
                ));
 }
コード例 #9
0
        public IUnit BuildUnit(IHexCell location, IUnitTemplate template, ICivilization owner, IPromotionTree promotionTree)
        {
            if (location == null)
            {
                throw new ArgumentNullException("location");
            }
            else if (template == null)
            {
                throw new ArgumentNullException("template");
            }
            else if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }

            var newUnitObject  = GameObject.Instantiate(UnitConfig.UnitPrefab);
            var newUnitDisplay = GameObject.Instantiate(template.DisplayPrefab);

            newUnitDisplay.transform.SetParent(newUnitObject.transform);

            Container.InjectGameObject(newUnitObject);

            var newUnit = newUnitObject.GetComponent <GameUnit>();

            newUnit.transform.SetParent(UnitContainer, false);

            newUnit.Template = template;

            newUnit.CurrentMovement  = template.MaxMovement;
            newUnit.CurrentHitpoints = newUnit.MaxHitpoints;
            newUnit.CanAttack        = true;
            newUnit.Level            = 1;
            newUnit.PromotionTree    = promotionTree;

            allUnits.Add(newUnit);

            if (UnitPossessionCanon.CanChangeOwnerOfPossession(newUnit, owner))
            {
                UnitPossessionCanon.ChangeOwnerOfPossession(newUnit, owner);
            }
            else
            {
                throw new UnitCreationException("The newly created unit cannot be assigned to its owner");
            }

            if (newUnit.CanRelocate(location))
            {
                newUnit.Relocate(location);
            }
            else
            {
                throw new UnitCreationException("The newly created unit cannot be placed at its location");
            }

            UnitSignals.NewUnitCreated.OnNext(newUnit);

            return(newUnit);
        }
コード例 #10
0
 public static void AddToPacket(IUnitTemplate template, Packet packet)
 {
     packet.AddUInt16((ushort)template.Size);
     foreach (var kvp in template)
     {
         packet.AddUInt16(kvp.Key);
         packet.AddByte(kvp.Value.Lvl);
     }
 }
コード例 #11
0
        private IUnit BuildUnit(
            IHexCell location, ICivilization owner, IUnitTemplate template,
            IPromotionTree promotionTree = null
            )
        {
            Mock <IUnit> mock;

            return(BuildUnit(location, owner, template, out mock, promotionTree));
        }
コード例 #12
0
        public IUnit BuildUnit(IHexCell location, IUnitTemplate template, ICivilization owner)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }

            return(BuildUnit(location, template, owner, new PromotionTree(template.PromotionTreeData)));
        }
コード例 #13
0
ファイル: UnitBuilder.cs プロジェクト: ElKalou/ArenaFight
    public MockUnitBuilder()
    {
        _unit = Substitute.For <IUnit>();

        _unitInfo = A.MockUnitInfoTemplate().Build();

        _unitTransform = A.RandomTransform();

        _selectable = Substitute.For <ISelectable>();
    }
コード例 #14
0
        public EstimationUnit(IUnitTemplate template)
        {
            CanAttack        = true;
            CurrentHitpoints = template.MaxHitpoints;
            Template         = template;

            CombatSummary = new UnitCombatSummary()
            {
                modifiersWhenAttacking = new List <ICombatModifier>(),
                modifiersWhenDefending = new List <ICombatModifier>()
            };
        }
コード例 #15
0
 public void MakeDictionnary()
 {
     unitsAvailable = new Dictionary <IUnitTemplate, int>();
     for (int i = 0; i < _factory.prefabs.Count; i++)
     {
         IUnitTemplate key = _factory.prefabs[i].template;
         if (!unitsAvailable.ContainsKey(key))
         {
             unitsAvailable.Add(key, i);
         }
     }
 }
コード例 #16
0
        private IUnit BuildUnit(IUnitTemplate template, IHexCell location)
        {
            var mockUnit = new Mock <IUnit>();

            mockUnit.Setup(unit => unit.Template).Returns(template);

            var newUnit = mockUnit.Object;

            MockUnitPositionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(location);

            return(newUnit);
        }
コード例 #17
0
        private IUnit BuildUnit(ICivilization owner, IUnitTemplate template, int currentHitpoints)
        {
            var mockUnit = new Mock <IUnit>();

            mockUnit.Setup(unit => unit.Template).Returns(template);
            mockUnit.Setup(unit => unit.CurrentHitpoints).Returns(currentHitpoints);

            var newUnit = mockUnit.Object;

            MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(owner);

            return(newUnit);
        }
コード例 #18
0
        private IUnit BuildUnit(IUnitTemplate template, IPromotionTree promotionTree, ICivilization owner)
        {
            var mockUnit = new Mock <IUnit>();

            mockUnit.Setup(unit => unit.Template).Returns(template);
            mockUnit.Setup(unit => unit.PromotionTree).Returns(promotionTree);

            var newUnit = mockUnit.Object;

            MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(owner);

            return(newUnit);
        }
コード例 #19
0
        public bool IsUnitResearchedForCiv(IUnitTemplate template, ICivilization civilization)
        {
            if (template == null)
            {
                throw new ArgumentNullException("template");
            }
            else if (civilization == null)
            {
                throw new ArgumentNullException("civilization");
            }

            return(GetResearchedUnits(civilization).Contains(template));
        }
コード例 #20
0
        private IHexCell GetValidNearbyCell(IHexCell centerCell, IUnitTemplate template, ICivilization owner)
        {
            for (int i = 0; i < 10; i++)
            {
                foreach (var nearbyCell in Grid.GetCellsInRing(centerCell, i))
                {
                    if (UnitFactory.CanBuildUnit(nearbyCell, template, owner))
                    {
                        return(nearbyCell);
                    }
                }
            }

            throw new InvalidOperationException("There is no cell within 10 cells of the argued location that can support this person");
        }
コード例 #21
0
        private IProductionProject BuildProject(IBuildingTemplate building, IUnitTemplate unit, int progress)
        {
            var mockProject = new Mock <IProductionProject>();

            mockProject.SetupAllProperties();

            mockProject.Setup(project => project.BuildingToConstruct).Returns(building);
            mockProject.Setup(project => project.UnitToConstruct).Returns(unit);

            var newProject = mockProject.Object;

            newProject.Progress = progress;

            return(newProject);
        }
コード例 #22
0
ファイル: Castle.cs プロジェクト: gjrfytn/Smash-Our-Faces
        public void PurchaseUnit(IUnitTemplate unitTemplate)
        {
            if (unitTemplate == null)
            {
                throw new System.ArgumentNullException(nameof(unitTemplate));
            }

            if (Owner == null)
            {
                throw new System.InvalidOperationException("Cannot purchase unit in neutral castle.");
            }

            Owner.PurchaseUnit(unitTemplate);

            _Map.Spawn(unitTemplate, this, Owner, false);
        }
コード例 #23
0
        private bool IsConditionMetByUnit(IUnitTemplate unit)
        {
            if (UnitRestriction == UnitRestrictionCategory.OfType)
            {
                bool hasArguedType = UnitTypeArguments.Contains(unit.Type);

                return(Restriction == RestrictionType.MustBe ? hasArguedType : !hasArguedType);
            }
            else if (UnitRestriction == UnitRestrictionCategory.OfName)
            {
                bool isArguedName = NameArguments.Any(name => name.Equals(unit.name));

                return(Restriction == RestrictionType.MustBe ? isArguedName : !isArguedName);
            }
            else
            {
                return(false);
            }
        }
        private IUnit BuildUnit(
            int hitpoints, UnitType type, IHexCell location,
            IUnitTemplate template, out Mock <IUnit> mock
            )
        {
            mock = new Mock <IUnit>();

            mock.SetupAllProperties();

            mock.Setup(unit => unit.Type).Returns(type);
            mock.Setup(unit => unit.Template).Returns(template);

            var newUnit = mock.Object;

            newUnit.CurrentHitpoints = hitpoints;

            MockUnitPositionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(location);

            return(newUnit);
        }
コード例 #25
0
        private IUnit BuildUnit(
            IHexCell location, ICivilization owner, IUnitTemplate template,
            out Mock <IUnit> mock, IPromotionTree promotionTree = null
            )
        {
            mock = new Mock <IUnit>();

            mock.SetupAllProperties();
            mock.Setup(unit => unit.Template).Returns(template);
            mock.Setup(unit => unit.PromotionTree).Returns(promotionTree);

            var newUnit = mock.Object;

            MockUnitPositionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(location);
            MockUnitPossessionCanon.Setup(canon => canon.GetOwnerOfPossession(newUnit)).Returns(owner);

            AllUnits.Add(newUnit);

            return(newUnit);
        }
コード例 #26
0
        public ProductionProject(
            IUnitTemplate unitToConstruct, IUnitFactory unitFactory,
            IPossessionRelationship <ICivilization, ICity> cityPossessionCanon,
            IPossessionRelationship <IHexCell, ICity> cityLocationCanon,
            IStartingExperienceLogic startingExperienceLogic,
            ILocalPromotionLogic localPromotionLogic
            )
        {
            if (unitToConstruct == null)
            {
                throw new ArgumentNullException("unitToConstruct");
            }

            UnitToConstruct         = unitToConstruct;
            UnitFactory             = unitFactory;
            CityPossessionCanon     = cityPossessionCanon;
            CityLocationCanon       = cityLocationCanon;
            StartingExperienceLogic = startingExperienceLogic;
            LocalPromotionLogic     = localPromotionLogic;
        }
コード例 #27
0
        public bool IsTemplateValidForCity(IUnitTemplate template, ICity city)
        {
            var cityLocation = CityLocationCanon.GetOwnerOfPossession(city);
            var cityOwner    = CityPossessionCanon.GetOwnerOfPossession(city);

            if (!UnitPositionCanon.CanPlaceUnitTemplateAtLocation(template, cityLocation, cityOwner))
            {
                return(false);
            }


            foreach (var resource in template.RequiredResources)
            {
                if (FreeResourcesLogic.GetFreeCopiesOfResourceForCiv(resource, cityOwner) <= 0)
                {
                    return(false);
                }
            }

            return(true);
        }
コード例 #28
0
        public bool CanPlaceUnitTemplateAtLocation(IUnitTemplate template, IHexCell location, ICivilization owner)
        {
            if (location == null)
            {
                return(true);
            }

            if (IsCellImpassableFor(template.MovementSummary, location, owner, false))
            {
                return(false);
            }
            else if (CellHasDomesticUnits(location, owner))
            {
                return(!LocationHasUnitBlockingType(location, template.Type));
            }
            else if (CellHasForeignUnits(location, owner))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #29
0
 public void SetDescriptionFrom(IUnitTemplate template)
 {
     DescriptionField.text = template.Description;
 }
コード例 #30
0
        public City(uint id,
                    IPlayer owner,
                    string name,
                    Position position,
                    ILazyResource resource,
                    byte radius,
                    decimal ap,
                    string defaultTheme,
                    string roadTheme,
                    string troopTheme,
                    string wallTheme,
                    IActionWorker worker,
                    CityNotificationManager notifications,
                    IReferenceManager references,
                    ITechnologyManager technologies,
                    ITroopManager troops,
                    IUnitTemplate template,
                    ITroopStubFactory troopStubFactory,
                    IDbManager dbManager,
                    IGameObjectFactory gameObjectFactory,
                    IActionFactory actionFactory,
                    BattleProcedure battleProcedure)
        {
            Id                     = id;
            Owner                  = owner;
            this.name              = name;
            this.radius            = radius;
            this.troopStubFactory  = troopStubFactory;
            this.dbManager         = dbManager;
            this.gameObjectFactory = gameObjectFactory;
            this.actionFactory     = actionFactory;
            this.battleProcedure   = battleProcedure;

            PrimaryPosition = position;
            AlignmentPoint  = ap;
            DefaultTheme    = defaultTheme;
            RoadTheme       = roadTheme;
            WallTheme       = wallTheme;
            TroopTheme      = troopTheme;
            Resource        = resource;

            Worker        = worker;
            Notifications = notifications;
            References    = references;
            Technologies  = technologies;
            Troops        = troops;
            Template      = template;

            #region Event Proxies

            Template.UnitUpdated += evtTemplate =>
            {
                if (Global.Current.FireEvents && DbPersisted)
                {
                    dbManager.Save(evtTemplate);
                }

                UnitTemplateUpdated(this, new EventArgs());
            };

            Troops.TroopAdded += stub => TroopAdded(this, new TroopStubEventArgs {
                Stub = stub
            });
            Troops.TroopRemoved += stub => TroopRemoved(this, new TroopStubEventArgs {
                Stub = stub
            });
            Troops.TroopUpdated += stub => TroopUpdated(this, new TroopStubEventArgs {
                Stub = stub
            });
            Troops.TroopUnitUpdated += stub => TroopUnitUpdated(this, new TroopStubEventArgs {
                Stub = stub
            });

            Worker.ActionRemoved += (stub, state) => ActionRemoved(this, new ActionWorkerEventArgs {
                State = state, Stub = stub
            });
            Worker.ActionStarted += (stub, state) => ActionStarted(this, new ActionWorkerEventArgs {
                State = state, Stub = stub
            });
            Worker.ActionRescheduled += (stub, state) => ActionRescheduled(this, new ActionWorkerEventArgs {
                State = state, Stub = stub
            });

            Resource.ResourcesUpdate += () =>
            {
                CheckUpdateMode();
                ResourcesUpdated(this, new EventArgs());
            };

            Technologies.TechnologyCleared  += OnTechnologyCleared;
            Technologies.TechnologyAdded    += OnTechnologyAdded;
            Technologies.TechnologyRemoved  += OnTechnologyRemoved;
            Technologies.TechnologyUpgraded += OnTechnologyUpgraded;

            References.ReferenceAdded   += (sender, args) => ReferenceAdded(this, args);
            References.ReferenceRemoved += (sender, args) => ReferenceRemoved(this, args);

            #endregion
        }