コード例 #1
0
ファイル: ActionHandler.cs プロジェクト: avidvid/OUP
 //Monster
 public void SetActiveMonster(ActiveMonsterType monster, Transform player, string environmentType)
 {
     _monster  = monster;
     _player   = player;
     _isInside = (environmentType == "Inside");
     _inCombat = (environmentType == "Combat");
 }
コード例 #2
0
 
 internal void AttackDealing(ActiveMonsterType monster, float dealAtt, string environmentType)
 {
     //Make monster Aware of player when being hit
     if (environmentType == "Inside")
     {
         monster.SawTarget = true;
     }
     else //Terrain & Combat
     {
         monster.AttackMode = true;
     }
     if (dealAtt <= 0)
     {
         _GUIManager.PrintMessage("No damage dealt!!!", Color.yellow);
         print("No damage dealt!!! Env:" + environmentType + " " + monster.SawTarget +
               " Att (" +
               _characterManager.CharacterSetting.AbilityAttack + ","
               + _characterManager.CharacterSetting.MagicAttack + ","
               + _characterManager.CharacterSetting.PoisonAttack + ") Def ("
               + monster.MonsterType.AbilityDefense + ","
               + monster.MonsterType.MagicDefense + ","
               + monster.MonsterType.PoisonDefense + ")");
         return;
     }
     monster.MonsterType.Health -= (int)dealAtt * 7; //Todo:Debug  remove this *#
     if (monster.MonsterType.Health <= 0)
     {
         _characterManager.AddCharacterSetting("Experience", monster.MonsterType.MaxHealth);
         monster.Alive = false;
         monster.gameObject.SetActive(false);
         var monsterCharacter = monster.MonsterType.GetCharacter();
         if (environmentType == "Combat")
         {
             var images = GameObject.Find("Capture").GetComponentsInChildren <Image>();
             if (images[1].enabled)
             {
                 if (_characterManager.CaptureMonsterById(monsterCharacter.Id))
                 {
                     _GUIManager.PrintMessage("The monster Got captured", Color.green);
                 }
             }
             //SceneManager.LoadScene(SceneSettings.SceneIdForTerrainView);
         }
         else
         {
             _building.BuildingDropItem(monster.transform.position, monsterCharacter.DropChance, monsterCharacter.DropItems);
         }
     }
     else
     {
         var healthBar = monster.transform.GetComponentsInChildren <Transform>()[1];
         healthBar.localScale =
             new Vector3((float)monster.MonsterType.Health / monster.MonsterType.MaxHealth / 3,
                         healthBar.localScale.y, healthBar.localScale.z);
     }
 }
コード例 #3
0
ファイル: MonsterMove.cs プロジェクト: avidvid/OUP
    // Use this for initialization
    void Start()
    {
        _active    = transform.GetComponent <ActiveMonsterType>();
        _character = _active.MonsterType.GetCharacter();

        _player   = GameObject.FindGameObjectWithTag("Player").GetComponent <Transform>();
        _renderer = transform.GetComponent <SpriteRenderer>();
        _animator = transform.GetComponent <Animator>();
        if (_character.IsAnimated)
        {
            _animator.runtimeAnimatorController = GetMoveAnimation();
        }
        else
        {
            SetMoveSprites();
            _renderer.sprite = _down;
        }
    }
コード例 #4
0
ファイル: ActionHandler.cs プロジェクト: avidvid/OUP
    // CastSpell Logic
    private void CastSpell(Vector3 source, ActiveMonsterType monster, float attackDealt)
    {
        var spell = new GameObject();

        spell.transform.position = new Vector3(source.x, source.y, -1);
        spell.transform.parent   = _player.parent.parent;
        spell.name = "Player Spell";
        var spellRenderer = spell.AddComponent <SpriteRenderer>();

        spellRenderer.sortingOrder = _player.GetComponent <SpriteRenderer>().sortingOrder + 1;
        spellRenderer.sprite       = _characterManager.GetSpellSprite();
        spell.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
        var spellManager = spell.AddComponent <SpellManager>();

        spellManager.Target      = monster;
        spellManager.AttackValue = attackDealt;
        spellManager.MonsterType = _isInside?"Inside": _inCombat ? "Combat" : "Terrain";
    }
コード例 #5
0
 private void CreateMonsters(Vector3 location)
    {
        GameObject monster = Instantiate(_monsterObj);
        monster.transform.position = location;
        monster.transform.SetParent(transform); 
        monster.name = "Monster " + monster.transform.position;


        var active = monster.GetComponent<ActiveMonsterType>();
        var spriteRenderer = monster.GetComponent<SpriteRenderer>();
        active.Location = location;
        active.Alive = true;
        active.Hidden = true;

        _monsters.Add(active);

        var monsterCharacter = SetMonsterTypeBasedOnRarity(monster.transform.position);

        spriteRenderer.sprite = monsterCharacter.GetSprite();

        if (monsterCharacter.Move == Character.CharacterType.Fly)
            spriteRenderer.sortingOrder = _baseSortIndex +  6;
        else
            spriteRenderer.sortingOrder = _baseSortIndex +  3;
        if (monsterCharacter.IsAnimated)
        {
            var animator = monster.GetComponent<Animator>();
            animator.runtimeAnimatorController = monsterCharacter.GetAnimator();
            animator.speed = monsterCharacter.Move == Character.CharacterType.Fly ? 1 : 0;
        }

        var monsterLevel = _characterManager.CharacterSetting.Level;
        if (monsterLevel < 3)
            monsterLevel += 2;
        RandomHelper.RangeMinMax(monsterLevel - 2, monsterLevel + 3);
        active.MonsterType = _characterManager.GenerateMonster(monsterCharacter, monsterLevel);

        var textLevelRenderer = monster.GetComponentInChildren<TextMeshPro>();
        textLevelRenderer.text = "Level " + active.MonsterType.Level;
        monster.GetComponentInChildren<MeshRenderer>().sortingOrder = spriteRenderer.sortingOrder + 1;
        //Hide the monster in the map till they get in the line of Sight
        monster.gameObject.SetActive(false);
    }
    private void UnCacheElements()
    {
        foreach (var element in _cache.FindPersist("VacantElement"))
        {
            var currentElement = GetElement(element.Location);
            if (currentElement != null)
                DestroyElement(currentElement, false);
        }
    }
    public IEnumerable<ActiveMonsterType> GetMonster(Vector3 pos, float radius)
    {
        pos.z = 0;
        foreach (var monster in _monsters)
        {
            if (monster.Alive)
            {
                var bLoc = monster.transform.position;
                //MapPos in between the monster 
                var viewLimit = monster.MonsterType.View;
                if (Math.Abs(radius) > 0)
                    viewLimit = radius;
                if (Vector2.Distance(pos, bLoc) < viewLimit)
                    yield return monster;
            }
        }
    }
    internal bool DestroyMonster(ActiveMonsterType monster, bool drop)
    {
        print("Killing Monster " + monster.Location + (drop?" Drop Item":" "));
        if (drop)
        {
            var deadPos = monster.Location;
            _cache.PersistAdd(new CacheContent()
                {
                    Location = deadPos,
                    ObjectType = "DeadMonster",
                    ExpirationTime = DateTime.Now.AddHours(-19)  
                }
            );
            var monsterCharacter = monster.MonsterType.GetCharacter();
            DeadMonster(monster.transform.position, monsterCharacter);
        }
        _monsters.Remove(monster);
        Destroy(monster.gameObject);
        return true;
    }
    private void UnCacheMonsters()
    {
        foreach (var monster in _cache.FindPersist("DeadMonster"))
        {
            foreach (var currentMonster in GetMonster(monster.Location, 3))
                DestroyMonster(currentMonster, false);
        }
    }
    public static Vector3 StringToVector3(string sVector)
    {
        // Remove the parentheses
        if (sVector.StartsWith("(") && sVector.EndsWith(")"))
        {
            sVector = sVector.Substring(1, sVector.Length - 2);
        }

        // split the items
        string[] sArray = sVector.Split(',');

        // store as a Vector3
        Vector3 result = new Vector3(
            Single.Parse(sArray[0]),
            Single.Parse(sArray[1]),
            Single.Parse(sArray[2]));

        return result;
    }
    //Digging
    public bool CreateDigging(Vector3 location,bool useTool)
    {
        if (useTool)
            if (!_inv.ElementToolUse())
                return false;
        GameObject dig = new GameObject();
        _digs.Add(dig);
        dig.transform.position = location;
        var renderer = dig.AddComponent<SpriteRenderer>();
        renderer.sprite = Dig;
        renderer.sortingOrder = _baseSortIndex + 1;
        dig.name = "Dig " + dig.transform.position;
        dig.transform.parent = transform;
        //print("CreateDigging : "+ dig.name);
        return true;
    }
    //Items
    public void CreateItem(Vector3 location, int itemId)
    {
        GameObject item = new GameObject();
        var active = item.AddComponent<ActiveItemType>();
        active.ItemTypeInUse = _itemDatabase.GetItemById(itemId);
        location.z -= 0.001f;
        active.Location = location;
        _activeItems.Add(active);
        item.transform.position = location;
        item.transform.localScale += new Vector3(0.1f, 0, 0);
        var renderer = item.AddComponent<SpriteRenderer>();
        renderer.sprite = active.ItemTypeInUse.GetSprite();
        renderer.sortingOrder =  _baseSortIndex+  2;
        item.name = active.ItemTypeInUse.Name + item.transform.position;
        item.transform.parent = transform;
    }