Exemplo n.º 1
0
    public void LoadNPCSceneData(List <NPCData> apc)
    {
        allNPCData = apc;
        foreach (GameObject c in allNPCsInScene)
        {
            if (c.tag.ToString() != "NPC")
            {
                continue;
            }


            foreach (NPCData data in allNPCData)
            {
                if (c.GetComponent <NPCInfo>().id == data.id)
                {
                    NPCInfo         a  = c.GetComponent <NPCInfo>();
                    Stats           s  = c.GetComponent <Stats>();
                    NPCSpeechHolder h  = c.GetComponent <NPCSpeechHolder>();
                    CombatScript    cs = c.GetComponent <CombatScript>();

                    c.transform.position = new Vector3(data.x, data.y, 0);
                    a.UpdateColliders();
                    a.direction = (CharacterInfo.Direction)data.direction;
                    a.state     = (CharacterInfo.MovementState)data.state;


                    cs.ProgressI = data.castProgress;
                    if (data.selectedSpellID != -1)
                    {
                        cs.selectedSpell = SpellManagerScript.ins.GetSpellFromID(data.selectedSpellID);
                    }
                    else
                    {
                        if (cs.spellCoroutine != null)
                        {
                            cs.StopCoroutine(cs.spellCoroutine);
                        }
                    }
                    cs.state       = (CombatScript.CombatState)data.combatState;
                    cs.energyState = (CombatScript.EnergyState)data.energyState;

                    a.id = data.id;
                    a.gameObject.SetActive(data.active);
                    a.canMove = data.canMove;
                    if (a.inCombat)
                    {
                        cs.AIEndCombat();
                    }
                    else
                    {
                        a.EnterCombat();
                    }
                    a.inCombat = data.inCombat;
                    a.SetStoppingDistance();
                    a.currentHealth     = data.currentHealth;
                    a.currentStamina    = data.currentStamina;
                    a.merchantMoney     = data.merchantMoney;
                    a.combatCooldown    = data.combatCooldown;
                    a.timeStoppedCombat = data.cooldown;

                    s.intuition    = data.intuition;
                    s.intelligence = data.intelligence;
                    s.strength     = data.strength;
                    s.charisma     = data.charisma;
                    s.precision    = data.precision;
                    s.dexterity    = data.dexterity;
                    s.perception   = data.perception;
                    s.attitude     = data.attitude;
                    s.fear         = data.fear;
                    s.danger       = data.danger;
                    s.spirituality = data.spirituality;

                    h.currentLine = data.currentLine;
                    h.currentSet  = data.currentSet;

                    a.merchantInventory.maxSize = data.maxSize;

                    a.merchantInventory.ClearInventory();
                    foreach (InventorySlotData invSlotData in data.inventory)
                    {
                        a.merchantInventory.AddItemCount(ItemManagerScript.ins.GetItemFromID(invSlotData.id), invSlotData.count);
                    }

                    a.movementType = (NPC.MovementType)data.moveType;

                    a.destination = new Vector3(data.areaPointX, data.areaPointY, 0);

                    foreach (GameObject p in new List <GameObject>(a.patrolPoints))
                    {
                        if (p.transform.position.x != data.patrolPointX || p.transform.position.y != data.patrolPointY)
                        {
                            a.patrolPoints.Remove(p);
                            a.patrolPoints.Add(p);
                        }
                        else
                        {
                            if (!a.inCombat)
                            {
                                if (a.movementType == NPC.MovementType.PATROL)
                                {
                                    a.polyNav.SetDestination(a.patrolPoints[0].transform.position);
                                }
                            }
                            break;
                        }
                    }
                    if (a.isWaiting)
                    {
                        //a.polyNav.Stop();
                        if (a.waitCoroutine != null)
                        {
                            a.StopCoroutine(a.waitCoroutine);
                        }
                    }
                    a.isWaiting = data.isWaiting;
                    a.isMoving  = data.isMoving;
                    if (a.isWaiting)
                    {
                        a.polyNav.Stop();
                        switch (a.movementType)
                        {
                        case NPC.MovementType.AREA:
                            a.waitCoroutine = a.StartCoroutine(a.StartWaitingArea());
                            break;

                        case NPC.MovementType.PATROL:
                            a.waitCoroutine = a.StartCoroutine(a.StartWaitingPatrol());
                            break;

                        default:
                            break;
                        }
                    }
                    break;
                }
            }
        }
    }