Beispiel #1
0
    private void OnDestroyed(System.Object obj)
    {
        IGameEntity     entity = (IGameEntity)obj;
        BasePlayer      owner  = BasePlayer.getOwner(entity);
        ResourcesPlacer placer = ResourcesPlacer.get(owner);

        if (entity.info.isUnit)
        {
            Unit unit = (Unit)entity;
            placer.RemoveEntity(WorldResources.Type.FOOD, entity);
        }
        else if (((BuildingInfo)entity.info).type != BuildingTypes.STRONGHOLD)
        {
            Resource resource = (Resource)entity;
            placer.RemoveEntity(GetElementFromResource(resource), entity);
        }

        placer.updatePopulation();
    }
Beispiel #2
0
    private void OnCreated(System.Object obj)
    {
        IGameEntity     entity = (IGameEntity)obj;
        EntityResources res    = entity.info.resources;

        Dictionary <WorldResources.Type, float> d = new Dictionary <WorldResources.Type, float>()
        {
            { WorldResources.Type.FOOD, res.food },
            { WorldResources.Type.WOOD, res.wood },
            { WorldResources.Type.METAL, res.metal }
        };

        BasePlayer      owner  = BasePlayer.getOwner(entity);
        ResourcesPlacer placer = ResourcesPlacer.get(owner);

        bool isUnit = entity.doIfUnit(unit =>
        {
            if (unit.type != UnitTypes.HERO)
            {
                placer.Buy(d);
            }
        });

        if (!isUnit)
        {
            if (((BuildingInfo)entity.info).type != BuildingTypes.STRONGHOLD)
            {
                placer.Buy(d);
            }
        }

        placer.updatePopulation();

        if (entity.info.isResource || entity.info.isUnit)
        {
            placer.StatisticsChanged(entity, CreatePackageFromEntity(entity));
        }
    }