Example #1
0
    void Start()
    {
        ActionLogPresenter.CreateInstance();
        ItemData.Load();
        EnemyData.Load();
        PlayerData.Load();

        //map 生成
        mapPresenter.Generate();

        //enemy生成
        List <UserModel> enemies = EnemyData.GetRandoms(50);

        enemies.ForEach(enemy =>
        {
            Vector2Int _pos  = mapPresenter.GetPopPoint();
            UserModel _model = characterListPresenter.Generate(_pos, mapPresenter.GetTileModel(_pos.x, _pos.y).floorId, enemy);
            mapPresenter.SetUserModel(_pos, _model);
        });

        //player生成
        UserModel player = PlayerData.GetRandom();

        player.isOwn = true;

        Vector2Int position = mapPresenter.GetPopPoint();
        UserModel  model    = characterListPresenter.Generate(position, mapPresenter.GetTileModel(position.x, position.y).floorId, player);

        mapPresenter.SetUserModel(position, model);

        gameStatus = new GameStatusModel();

        //item 配置
        List <ItemModel> items = ItemData.GetRandoms(50);

        items.ForEach(item => itemsListPresenter.Generate(mapPresenter, item));

        //階段配置
        stairsListPresenter.Generate(mapPresenter);

        //dummy エネミー配置
        //enemiesListPresenter.DummyGenerate(mapPresenter, mapPresenter.CanSetObject(pos));

        //dummy 階段配置
        Vector2Int pos = mapPresenter.GetPopPoint();

        stairsListPresenter.DummyGenerate(mapPresenter, mapPresenter.CanSetObject(pos));

        CharacterPresenter characterPresenter = characterListPresenter.GetOwnCharacterPresenter();

        characterPresenter.characterView.Equip("");
        menuPresenter.itemMenuPresenter.Initialize(characterPresenter.itemModels);

        //Create Hud
        GameObject res = Resources.Load("Object/Hud") as GameObject;
        GameObject obj = UnityEngine.Object.Instantiate(res, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;

        hudPresenter = obj.GetComponent <HudPresenter>();
        hudPresenter.UpdateHud(characterPresenter.status);
    }
Example #2
0
    //攻撃処理
    public void Attack(MapPresenter m, Dictionary <int, CharacterPresenter> characterListPresenter)
    {
        Vector3 pos = status.position + status.direction;

        if (pos.x < 0 || pos.z < 0)
        {
            return;
        }

        var vector2Int = new Vector2Int((int)pos.x, (int)pos.z);

        if (m.GetTileModel(vector2Int).charaType == TileModel.CharaType.Player ||
            m.GetTileModel(vector2Int).charaType == TileModel.CharaType.Enemy)
        {
            CharacterPresenter characterPresenter =
                characterListPresenter
                .FirstOrDefault(presenter => presenter.Key == m.GetTileModel(vector2Int).guid).Value;

            int damage = CalcAction.CalcAttack(status, characterPresenter.status);

            Debug.Log("Attack Damage : " + damage);
            characterPresenter.CalcHp(damage);
            Debug.Log("After Hp : " + characterPresenter.status.hp);

            ActionLogPresenter.Instance.ShowView();
            ActionLogPresenter.Instance.AddLog(LogType.Attack, new string[] { status.name, characterPresenter.status.name, damage.ToString() });
            if (characterPresenter.status.hp <= 0)
            {
                characterPresenter.Death();
            }
        }
        SetIsAction(true);

        characterView.Attack();
    }
Example #3
0
    private void ItemMenuAction(CharacterPresenter characterPresenter)
    {
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            menuPresenter.itemMenuPresenter.ChangeSelectedItem(1);
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            menuPresenter.itemMenuPresenter.ChangeSelectedItem(-1);
        }
        else if (Input.GetKeyDown(KeyCode.X))
        {
            if (characterPresenter.itemModels.Count > 0)
            {
                ItemModel item = menuPresenter.itemMenuPresenter.GetSelectedItemModel();

                // アイテム使用、削除
                characterPresenter.status.hp -= 10;
                characterPresenter.characterView.UpdateHud(characterPresenter.status.hp);
                characterPresenter.itemModels.Remove(
                    characterPresenter.itemModels.FirstOrDefault(i => i.guid == item.guid));

                ItemPresenter itemPresenter = itemsListPresenter.Find(item.guid);
                if (itemPresenter != null && characterPresenter.SetItem(itemPresenter.status))
                {
                    itemsListPresenter.Delete(itemPresenter);
                }

                menuPresenter.itemMenuPresenter.ShowView(false);
            }
        }
    }
Example #4
0
    private void Start()
    {
        characterPresenter = gameObject.GetComponent <CharacterPresenter>();
        myStats            = characterPresenter.MyStats;

        characterPresenter.AddStatusEffect(this);

        characterPresenter.MyStats.OnChangedCurrentHealth += CheckCurrentHealth;
    }
Example #5
0
 public void ShowLog()
 {
     foreach (KeyValuePair <int, CharacterPresenter> character in characterListPresenter)
     {
         //Debug.Log(enemy.Key);
         CharacterPresenter characterPresenter = character.Value;
         //Debug.Log(enemyPresenter.status.position.x + ":"+ enemyPresenter.status.position.z + "," + enemyPresenter.enemyView.trans.position.x + ":" + enemyPresenter.enemyView.trans.position.z);
     }
 }
Example #6
0
    public void Delete(CharacterPresenter characterPresenter)
    {
        int guid = characterPresenter.status.guid;

        if (characterPresenter != null)
        {
            Destroy(characterListObject[guid]);
            characterListPresenter.Remove(guid);
        }
        Debug.Log(characterListPresenter.Count);
    }
Example #7
0
    private void Start()
    {
        characterPresenter = gameObject.GetComponent <CharacterPresenter>();
        characterPresenter.AddStatusEffect(this);

        characterPresenter.MyStats.attackSpeed.AddModifier(attackSpeedModifier);
        characterPresenter.MyStats.criticalChance.AddModifier(criticalChanceModifier);
        characterPresenter.MyStats.criticalMultiplier.AddModifier(criticalPowerModifier);

        characterPresenter.MyStats.OnChangedCurrentHealth += SetAllAttackModifiersValue;
    }
Example #8
0
    //敵が全部動いたかどうか
    public bool IsAllAction()
    {
        bool is_end = true;

        foreach (KeyValuePair <int, CharacterPresenter> enemy in characterListPresenter.Where(presenter => presenter.Value.status.type == TileModel.CharaType.Enemy))
        {
            CharacterPresenter enemyPresenter = enemy.Value;
            if (enemyPresenter.status.isAction == false && enemyPresenter.isMove == true)
            {
                is_end = !is_end;
                break;
            }
        }

        return(is_end);
    }
Example #9
0
    public UserModel Generate(Vector2Int pos, int floorId, UserModel model)
    {
        GameObject res = Resources.Load("Object/" + model.modelName.Replace('_', '/')) as GameObject;
        GameObject obj = Object.Instantiate(res, new Vector3(pos.x, 0, pos.y), Quaternion.identity) as GameObject;

        obj.layer            = 9;
        obj.transform.parent = transform;

        CharacterPresenter characterPresenter = obj.GetComponent <CharacterPresenter>();

        characterPresenter.Initialize(model, serialGuid);

        characterPresenter.SetMapData(
            floorId,
            new Vector3(pos.x, 0, pos.y),
            new Vector3(0, 0, -1)
            );

        characterListPresenter[serialGuid] = characterPresenter;
        characterListObject[serialGuid]    = obj;
        serialGuid++;
        return(characterPresenter.status);
    }
Example #10
0
 private protected virtual void Start()
 {
     CharacterPresenter = GetComponent <CharacterPresenter>();
 }
Example #11
0
 public abstract void DisableMovement(CharacterPresenter characterPresenter);
Example #12
0
    private void Start()
    {
        characterPresenter = gameObject.GetComponent <CharacterPresenter>();

        characterPresenter.AddStatusEffect(this);
    }
Example #13
0
    private void DefaultAction(CharacterPresenter characterPresenter)
    {
        InputAxis axis    = InputAxis.GetInputAxis();
        bool      isShift = Input.GetKey(KeyCode.LeftShift);
        bool      isZ     = Input.GetKey(KeyCode.Z);

        //攻撃
        if (Input.GetKeyDown(KeyCode.X) && characterPresenter.status.isAction == false && !characterPresenter.isMove)
        {
            characterPresenter.Attack(mapPresenter, characterListPresenter.characterListPresenter);
            characterListPresenter.Delete();
            return;
        }

        if (axis.F.x != 0 || axis.F.y != 0)
        {
            if (isZ && (axis.F.x == 0 || axis.F.y == 0))
            {
                return;
            }
            // 向き変更
            if (!characterPresenter.isMove)
            {
                characterPresenter.SetDirection(new Vector3(axis.I.x, 0, axis.I.y));
                // shiftが押されていたら方向転換だけ
                if (isShift)
                {
                    return;
                }
            }

            Vector2Int beforePosition = new Vector2Int((int)characterPresenter.status.position.x, (int)characterPresenter.status.position.z);
            Vector2Int afterPosition  = new Vector2Int(beforePosition.x + axis.I.x, beforePosition.y + axis.I.y);

            if (mapPresenter.IsCanMove(axis.I, beforePosition, characterPresenter.status.type))
            {
                if (!characterPresenter.isMove && characterPresenter.status.isAction == false)
                {
                    if (!isShift)
                    {
                        characterPresenter.Move(axis.F.x, axis.F.y);

                        //アイテムがあれば取得
                        if (mapPresenter.GetTileModel(afterPosition.x, afterPosition.y).itemGuid != 0)
                        {
                            ItemPresenter itemPresenter = itemsListPresenter.Find(mapPresenter.GetTileModel(afterPosition.x, afterPosition.y).itemGuid);

                            if (itemPresenter != null && characterPresenter.SetItem(itemPresenter.status))
                            {
                                itemsListPresenter.Delete(itemPresenter);

                                mapPresenter.SetItemModel(afterPosition.x, afterPosition.y, null);
                            }
                            else
                            {
                                Debug.Log("Cant Delete:null");
                            }
                        }

                        //階段あれば移動
                        if (mapPresenter.GetTileModel(afterPosition)
                            .tileType == TileModel.TileType.Stairs)
                        {
                            mapPresenter.Regenerate();
                        }

                        //移動元と移動先にキャラクター情報を設定
                        mapPresenter.SetUserModel(beforePosition, null);
                        mapPresenter.SetUserModel(afterPosition, characterPresenter.status);

                        characterPresenter.SetPosition(new Vector3(afterPosition.x, 0, afterPosition.y));
                    }
                }
            }
        }
    }
Example #14
0
    //全ての敵に行動させる
    public void AllAction(MapPresenter mapPresenter)
    {
        // Dictionary<int, EnemyPresenter> plauerInSideFloorEnemy = enemyListPresenter.Select(enemy =>
        // enemy.Value.status.floorId == 0).ToDictionary(enemy => );

        Dictionary <int, CharacterPresenter> plauerInSideFloorEnemy  = new Dictionary <int, CharacterPresenter>();
        Dictionary <int, CharacterPresenter> plauerOutSideFloorEnemy = new Dictionary <int, CharacterPresenter>();

        /// TODO全プレイヤーで検索する
        CharacterPresenter player = characterListPresenter.FirstOrDefault(presenter => presenter.Value.status.type == TileModel.CharaType.Player).Value;


        //プレイヤーと同じフロアにいるかで分ける
        foreach (KeyValuePair <int, CharacterPresenter> enemy in characterListPresenter.Where(presenter => presenter.Value.status.type == TileModel.CharaType.Enemy))
        {
            enemy.Value.beforeStatus = enemy.Value.status;
            if (enemy.Value.status.floorId == player.status.floorId)
            {
                plauerInSideFloorEnemy.Add(enemy.Key, enemy.Value);
            }
            else
            {
                plauerOutSideFloorEnemy.Add(enemy.Key, enemy.Value);
            }
        }

        // プレイヤーに近い順に並べて行動させるようにソートする。
        foreach (KeyValuePair <int, CharacterPresenter> enemy in plauerInSideFloorEnemy)
        {
            //GetFirstPositionAStar(enemy.Value.status.position, playerPresenter.status.position, mapPresenter);
        }

        var around1   = new DirectionUtil().GetAroundDirection(1);
        var around100 = new DirectionUtil().GetAroundDirection(100);

        foreach (KeyValuePair <int, CharacterPresenter> enemy in characterListPresenter.Where(presenter => presenter.Value.status.type == TileModel.CharaType.Enemy))
        {
            CharacterPresenter characterPresenter = enemy.Value;

            // 周りにプレイヤーがいれば攻撃
            var searchDirection1  = around1.Select(i => i + characterPresenter.status.position.GetVector2Int());
            var hitEnemyDirection = searchDirection1.Where(i => mapPresenter.SearchCharaType(i, TileModel.CharaType.Player));

            if (hitEnemyDirection.Any())
            {
                Vector2Int direction = hitEnemyDirection.First() - characterPresenter.status.position.GetVector2Int();
                characterPresenter.SetDirection(direction.GetVector2Int());
                characterPresenter.Attack(mapPresenter, characterListPresenter);
                characterPresenter.SetIsAction(true);
                continue;
            }

            // 攻撃できなければランダムアクション
            int actionType = characterPresenter.GetAction();
            if (actionType == 1)
            {
                InputAxis axis = InputAxis.GetRandomAxis();
                //キャッシュに残るもので移動できるか、移動できなければ再計算
                if (characterPresenter.cacheNextDestination.Count > 0 && mapPresenter.IsCanMove(characterPresenter.cacheNextDestination.First() - characterPresenter.status.position.GetVector2Int(),
                                                                                                characterPresenter.status.position.GetVector2Int(), characterPresenter.status.type))
                {
                    axis = new InputAxis(characterPresenter.cacheNextDestination.First() -
                                         characterPresenter.status.position.GetVector2Int());
                    characterPresenter.cacheNextDestination.RemoveAt(0);
                }
                else
                {
                    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                    sw.Start();
                    //通路を検索
                    var to = mapPresenter.GetFloorModel(characterPresenter.status.floorId).innerPath.GetRandom();
                    if (to != Vector2Int.zero && to != characterPresenter.status.position.GetVector2Int())
                    {
                        var wayList = GetDestinationWayList(characterPresenter.status.position.GetVector2Int(), to,
                                                            mapPresenter, characterPresenter);
                        if (wayList.Length > 0)
                        {
                            axis = new InputAxis(wayList.First() - characterPresenter.status.position.GetVector2Int());
                            characterPresenter.cacheNextDestination = wayList.ToList();
                        }
                    }
                    sw.Stop();
                    Debug.Log(characterPresenter.status.guid + ",from:" + characterPresenter.status.position.GetVector2Int() + ",to:" + to + ",time:" + sw.ElapsedMilliseconds);
                }


                if (axis.I == new Vector2Int(0, 0))
                {
                    //移動先がなければ行動済みにする。
                    characterPresenter.SetIsAction(true);
                    continue;
                }

                if (!mapPresenter.IsCanMove(axis.I, characterPresenter.status.position.GetVector2Int(), characterPresenter.status.type))
                {
                    // TODO 移動先に邪魔なものがあれば縦か横移動をする。
                    characterPresenter.SetIsAction(true);
                    continue;
                }

                Vector2Int beforePosition = new Vector2Int((int)characterPresenter.status.position.x, (int)characterPresenter.status.position.z);
                Vector2Int afterPosition  = new Vector2Int(beforePosition.x + axis.I.x, beforePosition.y + axis.I.y);

                characterPresenter.Move(axis.F.x, axis.F.y);

                //移動元と移動先にキャラクター情報を設定
                mapPresenter.SetUserModel(beforePosition, null);
                mapPresenter.SetUserModel(afterPosition, characterPresenter.status);

                characterPresenter.SetMapData(
                    mapPresenter.GetTileModel(afterPosition).floorId,
                    new Vector3(afterPosition.x, 0, afterPosition.y),
                    new Vector3(axis.I.x, 0, axis.I.y)
                    );
            }
            else
            {
                //GetNearCharacterPosition(GameConfig.SearchType.Around8, TileModel.CharaType.Player, mapPresenter.map);
                characterPresenter.SetIsAction(true);
            }
        }
    }
Example #15
0
    private bool GetPositionAStar(AStarCost aStar, Vector2Int to, ref List <AStarCost> routeAStarList, ref List <AStarCost> cacheAStarCostList, MapPresenter mapPresenter, CharacterPresenter characterPresenter)
    {
        List <AStarCost> aroundAStarList = new List <AStarCost>();

        foreach (Vector2Int direction in _directions)
        {
            var p = aStar.position + direction;
            //cacheにあればOpenしない
            if (cacheAStarCostList.Any(aster => aster.position == p) || !mapPresenter.IsCanMoveAStar(direction, aStar.position, characterPresenter.status.type))
            {
                continue;
            }

            AStarCost nowNode = new AStarCost
            {
                position = p,
                cost     = aStar.cost + 1
            };
            nowNode.estimateCost = EstimateCost(nowNode.position, to);
            nowNode.distance     = DistanceCost(nowNode.position, to);
            nowNode.score        = nowNode.cost + nowNode.estimateCost;

            cacheAStarCostList.Add(nowNode);
            aroundAStarList.Add(nowNode);
            //目的地についたら
            if (nowNode.position == to)
            {
                routeAStarList.Add(nowNode);
                return(true);
            }
        }

        if (aroundAStarList.Count < 1)
        {
            return(false);
        }

        cacheAStarCostList.First(_ => _.position == aStar.position).status = 2;

        var nextAroundAStar = aroundAStarList.OrderBy(a => a.score).ThenBy(a => a.distance);

        foreach (var nextAStar in nextAroundAStar)
        {
            if (GetPositionAStar(nextAStar, to, ref routeAStarList, ref cacheAStarCostList, mapPresenter,
                                 characterPresenter))
            {
                routeAStarList.Add(nextAStar);
                return(true);
            }
        }
        return(false);
    }
Example #16
0
    private Vector2Int[] GetDestinationWayList(Vector2Int from, Vector2Int to, MapPresenter mapPresenter, CharacterPresenter characterPresenter)
    {
        AStarCost nowNode = new AStarCost();

        nowNode.position = from;

        nowNode.cost         = 0;
        nowNode.estimateCost = EstimateCost(nowNode.position, to);
        nowNode.score        = nowNode.cost + nowNode.estimateCost;

        var cacheAStarCostList = new List <AStarCost>()
        {
            nowNode
        };
        var routeAStarList = new List <AStarCost>();

        GetPositionAStar(nowNode, to, ref routeAStarList, ref cacheAStarCostList, mapPresenter, characterPresenter);
        if (routeAStarList.Count > 0)
        {
            routeAStarList.Reverse();
            return(routeAStarList.Select(_ => _.position).ToArray());
        }
        return(new Vector2Int[] { });
    }