Пример #1
0
    public static Entity BuyItem(ShellCore core, int index, IVendor vendor)
    {
        if (core.unitsCommanding.Count >= core.GetTotalCommandLimit())
        {
            return(null);
        }

        GameObject creation = new GameObject();

        creation.transform.position = vendor.GetPosition();
        var blueprint = vendor.GetVendingBlueprint();

        switch (blueprint.items[index].entityBlueprint.intendedType)
        {
        case EntityBlueprint.IntendedType.Turret:
            Turret tur = creation.AddComponent <Turret>();
            tur.blueprint = blueprint.items[index].entityBlueprint;
            core.SetTractorTarget(creation.GetComponent <Draggable>());
            tur.SetOwner(core);

            if (SectorManager.instance && SectorManager.instance.GetComponentInChildren <BattleZoneManager>())
            {
                var stats = SectorManager.instance.GetComponentInChildren <BattleZoneManager>().stats.Find(s => s.faction == core.faction);
                if (stats == null)
                {
                    stats = new BattleZoneManager.Stats(core.faction);
                    SectorManager.instance.GetComponentInChildren <BattleZoneManager>().stats.Add(stats);
                }
                stats.turretSpawns++;
            }
            break;

        case EntityBlueprint.IntendedType.Tank:
            Tank tank = creation.AddComponent <Tank>();
            tank.blueprint = blueprint.items[index].entityBlueprint;
            tank.SetOwner(core);
            break;

        default:
            break;
        }

        creation.GetComponent <Entity>().spawnPoint = vendor.GetPosition();
        creation.GetComponent <Entity>().faction    = core.faction;
        creation.name = blueprint.items[index].entityBlueprint.name;
        core.sectorMngr.InsertPersistentObject(blueprint.items[index].entityBlueprint.name, creation);
        core.AddPower(-blueprint.items[index].cost);
        return(creation.GetComponent <Entity>());
    }
Пример #2
0
    /// <summary>
    /// Creates a drone
    /// </summary>
    protected override void Execute()
    {
        AudioManager.PlayClipByID("clip_respawn", transform.position);

        // Spawn the drone
        GameObject go    = new GameObject(blueprint.name);
        Drone      drone = go.AddComponent <Drone>();

        drone.blueprint          = blueprint;
        drone.faction            = craft.GetFaction();
        drone.transform.position = part.transform.position;
        drone.spawnPoint         = part.transform.position;
        drone.type = spawnData.type;
        drone.Init();
        drone.SetOwner(craft);
        craft.GetSectorManager().InsertPersistentObject(drone.blueprint.name, go);
        if (SectorManager.instance && SectorManager.instance.GetComponentInChildren <BattleZoneManager>())
        {
            var stats = SectorManager.instance.GetComponentInChildren <BattleZoneManager>().stats.Find(s => s.faction == Core.faction);
            if (stats == null)
            {
                stats = new BattleZoneManager.Stats(Core.faction);
                SectorManager.instance.GetComponentInChildren <BattleZoneManager>().stats.Add(stats);
            }
            stats.droneSpawns++;
        }

        if (craft is ICarrier || craft is AirWeaponStation || craft is GroundWeaponStation)
        {
            drone.getAI().setMode(AirCraftAI.AIMode.Path);
        }
        else
        {
            if (drone.type != DroneType.Worker)
            {
                drone.getAI().follow(craft.GetTransform());
            }
            else
            {
                drone.getAI().setMode(AirCraftAI.AIMode.Tractor);
                drone.getAI().owner = craft;
            }
        }
    }