Пример #1
0
        protected WorldObject actor;  //Object that uses (is capable of) this action

        //private Texture2D cursorTex = null;
        //public Texture2D cursor { get { return ResourceManager.loadTexture(ref cursorTex, HoverCursor); } }

        public Action(string def, WorldObject act)
        {
            if (act)
            {
                actor = act;
            }
            else
            {
                Debug.LogError("Action with no parent object!");
            }

            if (def.Length > 0)
            {
                this.def = DefStorage.getDef(def) as ActionDef;
            }
            else
            {
                this.def = DefStorage.getDef(getDefName()) as ActionDef;
            }
            if (this.def == null)
            {
                this.def = new ActionDef();
            }
            //this.def = ResourceManager.
            menuImage = new LazyResource <Texture2D>(this.def.MenuIcon);
            //Init def
            //InitDef();
        }
Пример #2
0
        public void TestContributeNormal(
            ICity city,
            ICanDo canDo,
            IStructure structure,
            [FrozenMock] Formula formula,
            Fixture fixture)
        {
            var cityResources = new LazyResource(1000, 1000, 1000, 1000, 1000);
            var resource      = new Resource(100, 20, 50, 80, 1);
            var capacity      = new Resource(500, 500, 500, 500, 5);

            formula.GetContributeCapacity(structure).Returns(capacity);

            Resource contributedResources = null;

            city.Owner.Tribesman.Tribe.Contribute(123, Arg.Is <Resource>(contributed => contributed.CompareTo(resource) == 0))
            .Returns(Error.Ok)
            .AndDoes(callInfo =>
            {
                contributedResources = new Resource(callInfo.Arg <Resource>());
            });

            city.Id.Returns <uint>(1);
            city.Resource.Returns(cityResources);

            structure.GroupId.Returns <uint>(1);
            structure.ObjectId.Returns <uint>(100);
            structure.City.Returns(city);

            city.Owner.IsInTribe.Returns(true);
            city.Owner.PlayerId.Returns <uint>(123);

            var locator = new GameObjectLocatorStub(city, city.Owner.Tribesman.Tribe, structure);

            var action = new TribeContributeActiveAction(1, 100, resource, locator, formula, new LockerStub(locator))
            {
                WorkerObject = canDo,
                IsDone       = false
            };

            // Execute/Verify
            action.Execute().Should().Be(Error.Ok);
            cityResources.Crop.Value.Should().Be(900);
            cityResources.Gold.Value.Should().Be(980);
            cityResources.Iron.Value.Should().Be(950);
            cityResources.Wood.Value.Should().Be(920);
            cityResources.Labor.Value.Should().Be(999);

            action.Callback(null);
            contributedResources.Should().NotBeNull("Should have contributed resources");
            contributedResources.Crop.Should().Be(100);
            contributedResources.Gold.Should().Be(20);
            contributedResources.Iron.Should().Be(50);
            contributedResources.Wood.Should().Be(80);
            contributedResources.Labor.Should().Be(1);
        }
Пример #3
0
        public void TestContributeNotEnoughResource(
            ICity city,
            ICanDo canDo,
            IStructure structure,
            [Frozen] IGameObjectLocator locator,
            [FrozenMock] Formula formula,
            Fixture fixture)
        {
            var cityResources = new LazyResource(50, 50, 50, 50, 50);
            var capacity      = new Resource(500, 500, 500, 500, 5);
            var resource      = new Resource(100, 20, 50, 80, 1);

            fixture.Register(() => resource);

            formula.GetContributeCapacity(structure).Returns(capacity);
            structure.City.Returns(city);
            city.Resource.Returns(cityResources);
            city.Owner.IsInTribe.Returns(true);

            ICity      outCity;
            IStructure outStructure;

            locator.TryGetObjects(Arg.Any <uint>(), Arg.Any <uint>(), out outCity, out outStructure).Returns(callInfo =>
            {
                callInfo[2] = city;
                callInfo[3] = structure;
                return(true);
            });

            fixture.PickGreedyConstructor <TribeContributeActiveAction>();
            var action = fixture.Create <TribeContributeActiveAction>();

            action.WorkerObject = canDo;
            action.IsDone       = false;

            // Execute/Verify
            action.Execute().Should().Be(Error.ResourceNotEnough);

            cityResources.Crop.Value.Should().Be(50);
            cityResources.Gold.Value.Should().Be(50);
            cityResources.Iron.Value.Should().Be(50);
            cityResources.Wood.Value.Should().Be(50);
            cityResources.Labor.Value.Should().Be(50);

            city.Owner.Tribesman.Tribe.DidNotReceiveWithAnyArgs().Contribute(0, null);
        }
Пример #4
0
 /** Constructor **/
 public WorldObject()
 {
     hudImage = new LazyResource <Texture2D>(hudImagePath);
 }