示例#1
0
    private void InstantiateDebugGrid(Vector2i offset, Transform root)
    {
        var grid = new GameObject("debug grid");

        grid.transform.SetParent(root);
        grid.layer = UnityLayers.SpecialTiles;

        for (int y = 0; y < gridHeight; ++y)
        {
            for (int x = 0; x < gridWidth; ++x)
            {
                var cellObject = new GameObject(x + ", " + y);
                cellObject.transform.position = Iso.MapToWorld(
                    (x * gridX + offset.x) * Iso.SubTileCount - 2,
                    (y * gridY + offset.y) * Iso.SubTileCount - 2);
                cellObject.transform.SetParent(grid.transform);
                cellObject.layer = UnityLayers.SpecialTiles;
                var line = cellObject.AddComponent <LineRenderer>();
                line.startWidth    = 0.1f;
                line.endWidth      = 0.1f;
                line.material      = Materials.normal;
                line.useWorldSpace = false;
                var corners = new Vector3[] {
                    Iso.MapTileToWorld(0, 0),
                    Iso.MapTileToWorld(0 + gridX, 0),
                    Iso.MapTileToWorld(0 + gridX, gridY),
                    Iso.MapTileToWorld(0, gridY),
                    Iso.MapTileToWorld(0, 0)
                };
                line.positionCount = corners.Length;
                line.SetPositions(corners);
            }
        }
    }
示例#2
0
    void HandleKeyboard()
    {
        if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Space))
        {
            InventoryPanel.instance.visible = false;
            CharstatPanel.instance.visible  = false;
        }

        if (!CommandPrompt.instance.visible)
        {
            if (Input.GetKeyDown(KeyCode.Return))
            {
                CommandPrompt.instance.visible = true;
            }

            if (Input.GetKeyDown(KeyCode.I))
            {
                InventoryPanel.instance.visible ^= true;
            }

            if (Input.GetKeyDown(KeyCode.C))
            {
                CharstatPanel.instance.visible ^= true;
            }

            if (Input.GetKeyDown(KeyCode.R))
            {
                run ^= true;
            }

            // following section serves debugging purposes only
            if (Input.GetKeyDown(KeyCode.T))
            {
                for (int i = 0; i < 1; ++i)
                {
                    var tc = TreasureClass.sheet[Random.Range(0, TreasureClass.sheet.Count)];
                    if (tc.name == null)
                    {
                        continue;
                    }
                    int itemLevel = Random.Range(50, 100);
                    ItemDrop.Drop(tc.name, Iso.MapToWorld(IsoInput.mouseTile), itemLevel);
                }
            }
        }
        else
        {
            if (Input.GetKeyDown(KeyCode.Return))
            {
                CommandPrompt.instance.visible = false;
                CommandPrompt.instance.Execute();
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                CommandPrompt.instance.visible = false;
            }
        }
    }
示例#3
0
    void Update()
    {
        speed += info.accel * Time.deltaTime;
        float distance = speed * Time.deltaTime;
        var   posDiff  = dir * distance;
        var   newPos   = iso.pos + posDiff;
        var   hit      = CollisionMap.Raycast(iso.pos, newPos, distance, size: info.size, ignore: originator.gameObject);

        if (hit)
        {
            Character hitCharacter = null;
            if (hit.gameObject != null)
            {
                hitCharacter = hit.gameObject.GetComponent <Character>();
                if (hitCharacter != null)
                {
                    int damage = CalcDamage();
                    hitCharacter.TakeDamage(damage, originator);
                    if (info.progOverlay != null)
                    {
                        Overlay.Create(hitCharacter.gameObject, info.progOverlay);
                    }
                }
            }
            if (info.explosionMissile != null)
            {
                Missile.Create(info.explosionMissile, hit.pos, hit.pos, originator);
            }

            AudioManager.instance.Play(info.hitSound, Iso.MapToWorld(hit.pos));
            AudioManager.instance.Play(SoundInfo.GetHitSound(info.hitClass, hitCharacter), Iso.MapToWorld(hit.pos));

            if (info.clientHitFunc == "14")
            {
                // glacial spike, freezing arrow
                Missile.Create(info.clientHitSubMissileId[0], hit.pos, hit.pos, originator);
                int subMissileCount = Random.Range(3, 5);
                for (int i = 0; i < subMissileCount; ++i)
                {
                    var offset = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
                    Missile.Create(info.clientHitSubMissileId[1], hit.pos, hit.pos - offset, originator);
                }
            }

            // todo pierce is actually is pierce skill with a chance to pierce
            if ((!info.pierce || hitCharacter == null) && info.collideKill)
            {
                Destroy(gameObject);
            }
        }

        iso.pos = newPos;
    }
示例#4
0
        private static void OnMissileHit(Missile missile, Vector2 hitPos, GameObject gameObject)
        {
            var info       = missile.Info;
            var originator = missile.Originator;

            Unit hitUnit = null;

            if (gameObject != null)
            {
                hitUnit = gameObject.GetComponent <Unit>();
                if (hitUnit != null)
                {
                    int damage = CalcDamage(missile);
                    hitUnit.Hit(damage, originator);
                    if (info.progOverlay != null)
                    {
                        Overlay.Create(hitUnit.gameObject, info.progOverlay, false);
                    }
                }
            }
            if (info.explosionMissile != null)
            {
                Missile.Create(info.explosionMissile, hitPos, hitPos, originator);
            }

            AudioManager.instance.Play(info.hitSound, Iso.MapToWorld(hitPos));
            AudioManager.instance.Play(SoundInfo.GetHitSound(info.hitClass, hitUnit), Iso.MapToWorld(hitPos));

            if (info.clientHitFunc == "14")
            {
                // glacial spike, freezing arrow
                Missile.Create(info.clientHitSubMissileId[0], hitPos, hitPos, originator);
                int subMissileCount = Random.Range(3, 5);
                for (int i = 0; i < subMissileCount; ++i)
                {
                    var offset = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
                    Missile.Create(info.clientHitSubMissileId[1], hitPos, hitPos - offset, originator);
                }
            }
            else if (info.serverHitFunc == "29")
            {
                // Frozen orb
                Missile.CreateRadially(info.clientHitSubMissileId[0], missile.Iso.pos, originator, 16);
            }

            // todo pierce is actually is pierce skill with a chance to pierce
            if ((!info.pierce || hitUnit == null) && info.collideKill)
            {
                Destroy(missile.gameObject);
            }
        }
示例#5
0
 static public void DebugDrawPath(Vector2 from, List <Step> path)
 {
     if (path.Count > 0)
     {
         Debug.DrawLine(Iso.MapToWorld(from), Iso.MapToWorld(path[0].pos), Color.grey);
     }
     for (int i = 0; i < path.Count - 1; ++i)
     {
         Debug.DrawLine(Iso.MapToWorld(path[i].pos), Iso.MapToWorld(path[i + 1].pos));
     }
     if (path.Count > 0)
     {
         var center = Iso.MapToWorld(path[path.Count - 1].pos);
         Debug.DrawLine(center + Iso.MapToWorld(new Vector2(0, 0.15f)), center + Iso.MapToWorld(new Vector2(0, -0.15f)));
         Debug.DrawLine(center + Iso.MapToWorld(new Vector2(-0.15f, 0)), center + Iso.MapToWorld(new Vector2(0.15f, 0)));
     }
 }
示例#6
0
    void Update()
    {
        ControlUI();

        if (flush && (Input.GetMouseButton(0) || Input.GetMouseButton(1)))
        {
            return;
        }

        flush = false;

        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        ControlCharacter();

        if (Input.GetKeyDown(KeyCode.T))
        {
            for (int i = 0; i < 1; ++i)
            {
                var tc = TreasureClass.sheet[Random.Range(0, TreasureClass.sheet.Count)];
                if (tc.name == null)
                {
                    continue;
                }
                int itemLevel = Random.Range(50, 100);
                ItemDrop.Drop(tc.name, Iso.MapToWorld(IsoInput.mouseTile), itemLevel);
            }
        }

        if (Input.GetKeyDown(KeyCode.F8))
        {
            var pos      = Iso.MapToWorld(IsoInput.mousePosition);
            var teleport = World.SpawnObject("TP", pos);
            teleport.modeName = "OP";
        }

#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.Space) && Input.GetKey(KeyCode.LeftShift))
        {
            UnityEditor.EditorWindow.focusedWindow.maximized ^= true;
        }
#endif
    }
示例#7
0
    void Update()
    {
        HandleKeyboard();
        UpdateCamera();

        if (flush && (Input.GetMouseButton(0) || Input.GetMouseButton(1)))
        {
            return;
        }

        flush = false;

        if (EventSystem.current.IsPointerOverGameObject())
        {
            return;
        }

        ControlCharacter();

        // following section serves debugging purposes only
        if (Input.GetKeyDown(KeyCode.T))
        {
            for (int i = 0; i < 1; ++i)
            {
                var tc = TreasureClass.sheet[Random.Range(0, TreasureClass.sheet.Count)];
                if (tc.name == null)
                {
                    continue;
                }
                int itemLevel = Random.Range(50, 100);
                ItemDrop.Drop(tc.name, Iso.MapToWorld(IsoInput.mouseTile), itemLevel);
            }
        }

#if UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.Space) && Input.GetKey(KeyCode.LeftShift))
        {
            UnityEditor.EditorWindow.focusedWindow.maximized ^= true;
        }
#endif
    }
示例#8
0
文件: Pickup.cs 项目: r2d2m/Diablerie
        public static Pickup Create(Vector3 position, string flippyFile, string name, string title = null, int dir = 0)
        {
            position = Iso.MapToIso(position);
            if (!CollisionMap.Fit(position, out position, mask: CollisionLayers.Item))
            {
                Debug.LogError("Can't fit pickup");
                return(null);
            }
            position = Iso.MapToWorld(position);
            var gameObject = new GameObject(name);

            gameObject.transform.position = position;
            var spritesheet = DC6.Load(flippyFile);
            var animator    = gameObject.AddComponent <SpriteAnimator>();

            animator.sprites = spritesheet.GetSprites(dir);
            animator.loop    = false;
            var pickup = gameObject.AddComponent <Pickup>();

            pickup.title = title;
            return(pickup);
        }
示例#9
0
        public static Warp Create(int x, int y, LevelWarpInfo warpInfo, LevelInfo sourceLevel, LevelInfo targetLevel, Transform parent)
        {
            var offset = new Vector3(warpInfo.offsetX, warpInfo.offsetY);
            var pos    = new Vector3(x, y) * Iso.SubTileCount - new Vector3(2, 2) + offset;

            pos = Iso.MapToWorld(pos);

            var warpObject = new GameObject(targetLevel.levelWarp);

            warpObject.transform.position = pos;
            warpObject.transform.SetParent(parent);
            var warp = warpObject.AddComponent <Warp>();

            warp.sourceLevel   = sourceLevel;
            warp.targetLevel   = targetLevel;
            warp.info          = warpInfo;
            warp.transform     = warpObject.transform;
            warp.selectSize    = new Vector3(warpInfo.selectDX, warpInfo.selectDY) / Iso.pixelsPerUnit;
            warp.selectOffset  = new Vector3(warpInfo.selectX, -warpInfo.selectY) / Iso.pixelsPerUnit;
            warp.selectOffset += new Vector3(warp.selectSize.x, -warp.selectSize.y) / 2;
            warpInfo.instance  = warp;
            return(warp);
        }
示例#10
0
    public static Character SpawnMonster(MonStat monStat, Vector3 pos, Transform parent = null)
    {
        pos = Iso.MapToIso(pos);
        if (!CollisionMap.Fit(pos, out pos, monStat.ext.sizeX))
        {
            return(null);
        }
        pos = Iso.MapToWorld(pos);

        var monster = new GameObject(monStat.nameStr);

        monster.transform.SetParent(parent);
        monster.transform.position = pos;

        var character = monster.AddComponent <Character>();

        character.monStat     = monStat;
        character.title       = monStat.name;
        character.basePath    = @"data\global\monsters";
        character.token       = monStat.code;
        character.weaponClass = monStat.ext.baseWeaponClass;
        character.run         = false;
        character.walkSpeed   = monStat.speed;
        character.runSpeed    = monStat.runSpeed;
        character.size        = monStat.ext.sizeX;

        var monLvl = MonLvl.Find(monStat.level[0]);

        if (monLvl != null && !monStat.noRatio)
        {
            character.health = Random.Range(monLvl.hp[0] * monStat.stats[0].minHP, monLvl.hp[0] * monStat.stats[0].maxHP + 1) / 100;
        }
        else
        {
            character.health = Random.Range(monStat.stats[0].minHP, monStat.stats[0].maxHP + 1);
        }
        character.maxHealth = character.health;

        var animator = character.GetComponent <COFAnimator>();

        animator.equip = new string[monStat.ext.gearVariants.Length];
        for (int i = 0; i < animator.equip.Length; ++i)
        {
            var variants = monStat.ext.gearVariants[i];
            if (variants == null)
            {
                continue;
            }
            animator.equip[i] = variants[Random.Range(0, variants.Length)];
        }

        if (monStat.ai == "Npc")
        {
            monster.AddComponent <NpcController>();
        }
        else if (monStat.ai != "Idle" && monStat.ai != "NpcStationary")
        {
            monster.AddComponent <MonsterController>();
        }

        var body = monster.AddComponent <Rigidbody2D>();

        body.isKinematic = true;
        var collider = monster.AddComponent <CircleCollider2D>();

        collider.radius = monStat.ext.sizeX * Iso.tileSizeY;

        return(character);
    }
示例#11
0
    static bool CreateObject(SpawnPreset obj, int x, int y, int level, Transform root)
    {
        var pos = Iso.MapToWorld(x - 2, y - 2);

        if (obj.type == 2)
        {
            if (obj.objectId >= ObjectInfo.sheet.Count)
            {
                return(false);
            }
            ObjectInfo objectInfo   = ObjectInfo.sheet[obj.objectId];
            var        staticObject = World.SpawnObject(objectInfo, pos, parent: root);
            staticObject.modeName = obj.mode;
            return(true);
        }
        else
        {
            string      monPreset   = MonPreset.Find(obj.act, obj.id);
            MonStat     monStat     = null;
            SuperUnique superUnique = null;

            if (monPreset != null)
            {
                monStat = MonStat.Find(monPreset);
                if (monStat == null)
                {
                    superUnique = SuperUnique.Find(monPreset);
                }
            }
            else
            {
                monStat = MonStat.sheet[obj.id];
            }

            if (monStat != null)
            {
                World.SpawnMonster(monStat, pos, root);
                return(true);
            }

            if (superUnique != null)
            {
                var monster = World.SpawnMonster(superUnique.monStat, pos, root);
                monster.gameObject.name = superUnique.nameStr;
                monster.title           = superUnique.name;
                monster.level           = level;
                int minionCount = Random.Range(superUnique.minGrp, superUnique.maxGrp + 1);
                for (int i = 0; i < minionCount; ++i)
                {
                    var minion = World.SpawnMonster(superUnique.monStat, pos, root);
                    minion.level = level;
                }
                return(true);
            }

            if (obj.id == 10)
            {
                // Fallens
                for (int i = 0; i < 4; ++i)
                {
                    World.SpawnMonster("fallen1", pos, root);
                }
                return(true);
            }

            if (obj.id == 11)
            {
                // Fallen shaman + fallens
                Spawn(MonStat.Find("fallenshaman1"), x, y, level, root);
                for (int i = 0; i < 4; ++i)
                {
                    var fallen = World.SpawnMonster("fallen1", pos, root);
                    fallen.level = level;
                }
                return(true);
            }

            if (obj.id == 27)
            {
                // Fallen shaman
                Spawn(MonStat.Find("fallenshaman1"), x, y, level, root);
                return(true);
            }

            return(false);
        }
    }
示例#12
0
    public void Use(MiscInfo itemInfo)
    {
        Debug.Log("Use item " + itemInfo.name + ", function: " + itemInfo.useFunction);
        switch (itemInfo.useFunction)
        {
        case MiscInfo.UseFunction.None:
            break;

        case MiscInfo.UseFunction.IdentifyItem:
            break;

        case MiscInfo.UseFunction.TownPortal:
            var pos      = Iso.MapToWorld(iso.pos);
            var teleport = World.SpawnObject("TP", pos, fit: true);
            teleport.modeName = "OP";
            var sound = SoundInfo.Find("player_townportal_cast");
            AudioManager.instance.Play(sound, pos);
            break;

        case MiscInfo.UseFunction.Potion:
            if (itemInfo.stat1 == "hpregen")
            {
                character.health += itemInfo.calc1;
            }
            if (itemInfo.stat1 == "manarecovery")
            {
                character.mana += itemInfo.calc1;
            }
            break;

        case MiscInfo.UseFunction.RejuvPotion:
            if (itemInfo.stat1 == "hitpoints")
            {
                character.health += (int)(itemInfo.calc1 / 100.0f * character.maxHealth);
            }
            if (itemInfo.stat1 == "mana")
            {
                character.mana += (int)(itemInfo.calc1 / 100.0f * character.maxMana);
            }
            if (itemInfo.stat2 == "hitpoints")
            {
                character.health += (int)(itemInfo.calc2 / 100.0f * character.maxHealth);
            }
            if (itemInfo.stat2 == "mana")
            {
                character.mana += (int)(itemInfo.calc2 / 100.0f * character.maxMana);
            }
            break;

        case MiscInfo.UseFunction.TemporaryPotion:
            break;

        case MiscInfo.UseFunction.HoradricCube:
            break;

        case MiscInfo.UseFunction.Elixir:
            break;

        case MiscInfo.UseFunction.StaminaPotion:
            break;
        }
    }
示例#13
0
    void Process(string input)
    {
        if (input == "")
        {
            return;
        }

        if (history.Count == 0 || history[history.Count - 1] != input)
        {
            history.Add(input);
        }

        string[] parts = input.Split(' ');
        if (parts.Length >= 2 && parts[0] == "/spawn")
        {
            var pos = Iso.MapToWorld(IsoInput.mouseTile);
            if (parts[1] == "pickup")
            {
                string flippyFile = @"data\global\items\flp" + parts[2] + ".dc6";
                Pickup.Create(pos, flippyFile, flippyFile);
                return;
            }

            if (parts[1] == "item")
            {
                string code = parts[2];
                ItemDrop.Drop(code, pos, 100);
                return;
            }

            if (parts[1] == "itemset")
            {
                string subname = parts[2];
                var    set     = ItemSet.sheet.Find(s => s.id.ToLower().Contains(subname));
                if (set != null)
                {
                    foreach (var setItem in set.items)
                    {
                        var item = Item.Create(setItem.itemCode);
                        item.quality    = Item.Quality.Set;
                        item.level      = setItem.level;
                        item.identified = false;
                        ItemDrop.GenerateSetItem(item);
                        Pickup.Create(pos, item);
                    }
                }
                return;
            }

            var id = parts[1];

            var objectInfo = ObjectInfo.Find(id);
            if (objectInfo != null)
            {
                var obj = World.SpawnObject(objectInfo, pos, fit: true);
                if (obj != null && parts.Length > 2)
                {
                    obj.modeName = parts[2];
                }
                return;
            }

            World.SpawnMonster(id, pos);
        }
        else
        {
            Debug.LogWarning(input);
        }
    }
示例#14
0
        void Execute(string input)
        {
            if (input == "")
            {
                return;
            }

            if (history.Count == 0 || history[history.Count - 1] != input)
            {
                history.Add(input);
            }

            string[] parts = input.Split(' ');
            if (parts.Length >= 2 && parts[0] == "/spawn")
            {
                var pos = Iso.MapToWorld(IsoInput.mouseTile);
                if (parts[1] == "pickup")
                {
                    string flippyFile = @"data\global\items\flp" + parts[2] + ".dc6";
                    Pickup.Create(pos, flippyFile, flippyFile);
                    return;
                }

                if (parts[1] == "item")
                {
                    string subname    = parts[2].ToLower();
                    var    uniqueItem = UniqueItem.sheet.Find(s => s.nameStr.ToLower().Contains(subname));
                    if (uniqueItem != null)
                    {
                        ItemDrop.Drop(uniqueItem, pos);
                    }
                    else
                    {
                        string code = parts[2];
                        ItemDrop.Drop(code, pos, 100);
                    }

                    return;
                }

                if (parts[1] == "itemset")
                {
                    string subname = parts[2].ToLower();
                    var    set     = ItemSet.sheet.Find(s => s.id.ToLower().Contains(subname));
                    if (set != null)
                    {
                        foreach (var setItem in set.items)
                        {
                            ItemDrop.Drop(setItem, pos);
                        }
                    }
                    return;
                }

                var id = parts[1];

                var objectInfo = ObjectInfo.Find(id);
                if (objectInfo != null)
                {
                    var obj = WorldBuilder.SpawnObject(objectInfo, pos, fit: true);
                    if (obj != null && parts.Length > 2)
                    {
                        obj.modeName = parts[2];
                    }
                }
                else
                {
                    int monsterCount = parts.Length > 2 ? int.Parse(parts[2]) : 1;
                    for (int i = 0; i < monsterCount; ++i)
                    {
                        WorldBuilder.SpawnMonster(id, pos);
                    }
                }
            }
            else if (parts.Length == 2 && parts[0] == "/act")
            {
                if (int.TryParse(parts[1], out int actNumber))
                {
                    WorldBuilder.GoToAct(actNumber);
                }
            }
            else if (parts.Length == 2 && parts[0] == "/addstate")
            {
                string stateCode = parts[1];
                var    stateInfo = StateInfo.FindByCode(stateCode);
                if (stateInfo != null)
                {
                    var player = WorldState.instance.Player.gameObject;
                    Overlay.Create(player, stateInfo.castoverlay, loop: false);
                    Overlay.Create(player, stateInfo.overlay1, loop: true);
                    Overlay.Create(player, stateInfo.overlay2, loop: true);
                    Overlay.Create(player, stateInfo.overlay3, loop: true);
                    Overlay.Create(player, stateInfo.overlay4, loop: true);
                }
            }
            else
            {
                Debug.LogWarning(input);
            }
        }
示例#15
0
        void Update()
        {
            lifeTime += Time.deltaTime;
            if (lifeTime > info.lifeTime)
            {
                if (info.serverHitFunc == "29")
                {
                    Missile.CreateRadially(info.clientHitSubMissileId[0], iso.pos, originator, 16);
                }
                Destroy(gameObject);
            }

            speed += Mathf.Clamp(info.accel * Time.deltaTime, 0, info.maxVelocity);
            float distance = speed * Time.deltaTime;
            var   posDiff  = dir * distance;
            var   newPos   = iso.pos + posDiff;
            var   hit      = CollisionMap.Raycast(iso.pos, newPos, distance, size: info.size, ignore: originator.gameObject);

            if (hit)
            {
                Character hitCharacter = null;
                if (hit.gameObject != null)
                {
                    hitCharacter = hit.gameObject.GetComponent <Character>();
                    if (hitCharacter != null)
                    {
                        int damage = CalcDamage();
                        hitCharacter.TakeDamage(damage, originator);
                        if (info.progOverlay != null)
                        {
                            Overlay.Create(hitCharacter.gameObject, info.progOverlay, false);
                        }
                    }
                }
                if (info.explosionMissile != null)
                {
                    Missile.Create(info.explosionMissile, hit.pos, hit.pos, originator);
                }

                AudioManager.instance.Play(info.hitSound, Iso.MapToWorld(hit.pos));
                AudioManager.instance.Play(SoundInfo.GetHitSound(info.hitClass, hitCharacter), Iso.MapToWorld(hit.pos));

                if (info.clientHitFunc == "14")
                {
                    // glacial spike, freezing arrow
                    Missile.Create(info.clientHitSubMissileId[0], hit.pos, hit.pos, originator);
                    int subMissileCount = Random.Range(3, 5);
                    for (int i = 0; i < subMissileCount; ++i)
                    {
                        var offset = new Vector2(Random.Range(-1f, 1f), Random.Range(-1f, 1f));
                        Missile.Create(info.clientHitSubMissileId[1], hit.pos, hit.pos - offset, originator);
                    }
                }
                else if (info.serverHitFunc == "29")
                {
                    // Frozen orb
                    Missile.CreateRadially(info.clientHitSubMissileId[0], iso.pos, originator, 16);
                }

                // todo pierce is actually is pierce skill with a chance to pierce
                if ((!info.pierce || hitCharacter == null) && info.collideKill)
                {
                    Destroy(gameObject);
                }
            }

            if (info.serverDoFunc == 15)
            {
                // Frozen orb
                int   frequency          = info.parameters[0].value * 25;
                float spawnPeriod        = 1.0f / frequency;
                float directionIncrement = info.parameters[1].value * 25 * Mathf.PI;
                int   missileToSpawn     = (int)((lifeTime + Time.deltaTime) / spawnPeriod) - (int)(lifeTime / spawnPeriod);
                for (int i = 0; i < missileToSpawn; ++i)
                {
                    var dir    = new Vector2(1, 0);
                    var rot    = Quaternion.AngleAxis(lifeTime * directionIncrement, new Vector3(0, 0, 1));
                    var offset = (Vector2)(rot * dir);
                    Missile.Create(info.clientSubMissileId[0], iso.pos, iso.pos + offset, originator);
                }
            }

            iso.pos = newPos;
        }
示例#16
0
        public static Unit SpawnMonster(MonStat monStat, Vector3 pos, Transform parent = null, Unit summoner = null)
        {
            pos = Iso.MapToIso(pos);
            if (!CollisionMap.Fit(pos, out pos, monStat.ext.sizeX))
            {
                return(null);
            }

            var monster = new GameObject(monStat.nameStr);

            monster.transform.SetParent(parent);
            monster.transform.position = Iso.MapToWorld(pos);

            CollisionMap.Move(pos, pos, monStat.ext.sizeX, monster);

            var unit = monster.AddComponent <Unit>();

            unit.monStat     = monStat;
            unit.title       = monStat.name;
            unit.basePath    = @"data\global\monsters";
            unit.token       = monStat.code;
            unit.weaponClass = monStat.ext.baseWeaponClass;
            unit.run         = false;
            unit.walkSpeed   = monStat.speed;
            unit.runSpeed    = monStat.runSpeed;
            unit.size        = monStat.ext.sizeX;
            unit.killable    = monStat.killable;

            var monLvl = MonLvl.Find(monStat.level[0]);

            if (monLvl != null && !monStat.noRatio)
            {
                unit.health = Random.Range(monLvl.hp[0] * monStat.stats[0].minHP, monLvl.hp[0] * monStat.stats[0].maxHP + 1) / 100;
            }
            else
            {
                unit.health = Random.Range(monStat.stats[0].minHP, monStat.stats[0].maxHP + 1);
            }
            unit.maxHealth = unit.health;

            var animator = unit.GetComponent <COFAnimator>();

            animator.equip = new string[monStat.ext.gearVariants.Length];
            for (int i = 0; i < animator.equip.Length; ++i)
            {
                var variants = monStat.ext.gearVariants[i];
                if (variants == null)
                {
                    continue;
                }
                animator.equip[i] = variants[Random.Range(0, variants.Length)];
            }

            if (summoner != null)
            {
                unit.party = summoner.party;
                var petController = monster.AddComponent <PetController>();
                petController.owner = summoner;
            }
            else if (monStat.ai == "Npc" || monStat.ai == "Towner" || monStat.ai == "Vendor" || monStat.ai == "Hireable")
            {
                unit.party = Party.Good;
                monster.AddComponent <NpcController>();
            }
            else if (monStat.ai != "Idle" && monStat.ai != "NpcStationary")
            {
                unit.party = Party.Evil;
                monster.AddComponent <MonsterController>();
            }

            var body = monster.AddComponent <Rigidbody2D>();

            body.isKinematic = true;
            var collider = monster.AddComponent <CircleCollider2D>();

            collider.radius = monStat.ext.sizeX * Iso.tileSizeY;

            return(unit);
        }