Exemplo n.º 1
0
        public void Update(NPCInfo ob)
        {
            if (GameScene.Game.MapControl.MapInfo == null)
            {
                return;
            }

            DXControl control;

            if (!MapInfoObjects.TryGetValue(ob, out control))
            {
                if (ob.Region?.Map != GameScene.Game.MapControl.MapInfo)
                {
                    return;
                }

                control         = GameScene.Game.GetNPCControl(ob);
                control.Parent  = Image;
                control.Opacity = Opacity;

                MapInfoObjects[ob] = control;
            }
            else if ((QuestIcon)control.Tag == ob.CurrentIcon)
            {
                return;
            }

            control.Dispose();
            MapInfoObjects.Remove(ob);
            if (ob.Region?.Map != GameScene.Game.MapControl.MapInfo)
            {
                return;
            }

            control            = GameScene.Game.GetNPCControl(ob);
            control.Parent     = Image;
            control.Opacity    = Opacity;
            MapInfoObjects[ob] = control;

            if (ob.Region.PointList == null)
            {
                ob.Region.CreatePoints(GameScene.Game.MapControl.Width);
            }

            int minX = GameScene.Game.MapControl.Width, maxX = 0, minY = GameScene.Game.MapControl.Height, maxY = 0;

            foreach (Point point in ob.Region.PointList)
            {
                if (point.X < minX)
                {
                    minX = point.X;
                }
                if (point.X > maxX)
                {
                    maxX = point.X;
                }

                if (point.Y < minY)
                {
                    minY = point.Y;
                }
                if (point.Y > maxY)
                {
                    maxY = point.Y;
                }
            }

            int x = (minX + maxX) / 2;
            int y = (minY + maxY) / 2;


            control.Location = new Point((int)(ScaleX * x) - control.Size.Width / 2, (int)(ScaleY * y) - control.Size.Height / 2);
        }
Exemplo n.º 2
0
    public bool     SetNPCInfo(NPCInfo npcInfo)
    {
        m_NPCInfo = npcInfo;

        return(true);
    }
Exemplo n.º 3
0
    void OnGUI()
    {
        this.Repaint();
        if (null == NPCInfoTableAsset)
        {
            TextAsset asset = GameData.LoadConfig <TextAsset>("NPCInfoTable");
            NPCInfoTableAsset = new NPCInfoTable();
            NPCInfoTableAsset.Load(asset.bytes);
            foreach (var item in NPCInfoTableAsset.m_list.Values)
            {
                npcNameList.Add(item.StrName);
                npcIDList.Add(item.ID);
            }
        }
        if (null == ModelInfoTableAsset)
        {
            TextAsset obj = GameData.LoadConfig <TextAsset>("ModelInfoTable");
            ModelInfoTableAsset = new ModelInfoTable();
            ModelInfoTableAsset.Load(obj.bytes);
        }
        EditorGUILayout.LabelField("NPC列表:", GUILayout.Width(100f));
        m_index = EditorGUILayout.Popup("NPC名称", m_index, npcNameList.ToArray());
        EditorGUILayout.FloatField(LABEL_SAMPLE_INT, npcIDList[m_index]);
        Rect rct = new Rect(155, 60, 40, 30);

        if (GUI.Button(rct, @"Add"))
        {
            int npcStaticID = npcIDList[m_index];
            if (Application.isPlaying)
            {
                Debug.Log("Add NPC:name(" + npcNameList[m_index].ToString() + ") npcID(" + npcStaticID.ToString() + ")");
                Actor npcActor = ActorManager.Singleton.CreatePureActor(ActorType.enNPC, m_dynamicIDSeed++, CSItemGuid.Zero, npcStaticID);
                npcActor.IDInTable = npcStaticID;
                npcActor.Props.SetProperty_Int32(ENProperty.islive, 1);;
                NPC       npc       = npcActor as NPC;
                NPCInfo   info      = NPCInfoTableAsset.Lookup(npcStaticID);
                ModelInfo modelinfo = ModelInfoTableAsset.Lookup(info.ModelId);
                if (info.Type == (int)ENNpcType.enBoxNPC)
                {
                    GameObject tempBody = GameData.LoadActor <GameObject>(modelinfo.ModelFile);
                    GameObject body     = GameObject.Instantiate(tempBody) as GameObject;
                    body.name = "body";
                    body.transform.position = Vector3.zero;
                    npc.SetBodyObject(body);
                }
                npcActor.CreateNeedModels();
                Vector3 pos = Vector3.zero;
                pos = new Vector3(ActorManager.Singleton.MainActor.MainObj.transform.position.x, 0.0f, ActorManager.Singleton.MainActor.MainObj.transform.position.z);
                npcActor.MainPos          = pos;
                npcActor.m_startAttackPos = pos;
                npcActor.UpdateHPBar();
            }
            else
            {
                NPCInfo    info      = NPCInfoTableAsset.Lookup(npcStaticID);
                ModelInfo  modelinfo = ModelInfoTableAsset.Lookup(info.ModelId);
                GameObject tempBody  = GameData.LoadActor <GameObject>(modelinfo.ModelFile);
                if (null != tempBody)
                {
                    GameObject body = GameObject.Instantiate(tempBody) as GameObject;
                    body.name = "body";
                }
            }
        }
    }
Exemplo n.º 4
0
    //打开
    void Open(bool isTest = false, int testID = 0, Info.ENTabelType testType = Info.ENTabelType.enNone)
    {
        Delete();
        Info.ENTabelType type = Info.ENTabelType.enNone;
        int        modelID = 0, weaponID = 0;
        List <int> allSkillIDList = new List <int>();
        int        id             = 0;

        if (isTest)
        {//测试用
            id = testID;
            if (testType == Info.ENTabelType.enHero)
            {
                type = Info.ENTabelType.enHero;
                HeroInfo heroInfo = m_heroTabel.Lookup(id);
                modelID        = heroInfo.ModelId;
                weaponID       = heroInfo.WeaponId;
                allSkillIDList = heroInfo.GetAllSkillIDList();
            }
            else
            {
                type = Info.ENTabelType.enNPC;
                NPCInfo npcInfo = m_npcTabel.Lookup(id);
                modelID  = npcInfo.ModelId;
                weaponID = npcInfo.WeaponID;
                allSkillIDList.AddRange(npcInfo.SkillList);
                allSkillIDList.Add(npcInfo.StaminaSkillID);
            }
        }
        else
        {
            id = m_idList[m_index];
            if (m_tableIndex == 0)
            {
                type = Info.ENTabelType.enHero;
                HeroInfo heroInfo = m_heroTabel.Lookup(id);
                modelID        = heroInfo.ModelId;
                weaponID       = heroInfo.WeaponId;
                allSkillIDList = heroInfo.GetAllSkillIDList();
            }
            else
            {
                type = Info.ENTabelType.enNPC;
                NPCInfo npcInfo = m_npcTabel.Lookup(id);
                modelID  = npcInfo.ModelId;
                weaponID = npcInfo.WeaponID;
                allSkillIDList.AddRange(npcInfo.SkillList);
                allSkillIDList.Add(npcInfo.StaminaSkillID);
            }
        }

        ModelInfo modelInfo = m_modelTable.Lookup(modelID);

        if (modelInfo == null)
        {
            Debug.LogError("model error,modelID:" + modelID + ",card id:" + id + ",type:" + type.ToString());
            return;
        }
        WeaponInfo weaponInfo = m_weaponTable.Lookup(weaponID);

        if (weaponInfo == null)
        {
            Debug.LogError("weapon error,weaponID:" + weaponID + ",card id:" + id + ",type:" + type.ToString());
            return;
        }

        m_currentInfo.m_tabelType  = type;
        m_currentInfo.m_tabelID    = id;
        m_currentInfo.m_modelType  = modelInfo.modelType;
        m_currentInfo.m_weaponType = (int)weaponInfo.WeaponType;
        List <int> skillIDList = new List <int>();

        foreach (var item in allSkillIDList)
        {//删除相同的技能id
            if (!skillIDList.Contains(item))
            {
                skillIDList.Add(item);
            }
        }
        GetAnimationList(skillIDList);

        //加载模型,并给模型加一个父
        GameObject parentObj = new GameObject();

        m_currentObj = parentObj;
        parentObj.transform.parent = ObjPanel.transform;
        GameObject modelObj = GameObject.Instantiate(GameData.LoadPrefab <GameObject>(modelInfo.ModelFile)) as GameObject;

        modelObj.name = "body";
        ObjEffect.GetComponent <EDSkillEventTrigger>().MainObj = modelObj;
        parentObj.name            = modelObj.name + "_parent";
        modelObj.transform.parent = parentObj.transform;

        parentObj.AddComponent <AnimationCameraCallback>();
        parentObj.AddComponent <AnimationEffectCallback>();
        parentObj.AddComponent <AnimationEndCallback>();
        parentObj.AddComponent <AnimationShaderParamCallback>();
        parentObj.AddComponent <AnimationSoundCallback>();
        parentObj.AddComponent <BreakPointCallback>();
        parentObj.AddComponent <AttackActionCallback>();
        #region//加载模型的父的animation
        Animation parentAnim = parentObj.AddComponent <Animation>();
        string    path       = "Assets/Resources/SkillAnim/";
        foreach (var item in m_skillAnimList)
        {
            Info.AnimInfo info = null;
            m_currentInfo.m_animMap.TryGetValue(item, out info);

            string filename = m_currentInfo.m_modelType.ToString() + "-" +
                              m_currentInfo.m_weaponType.ToString() + "-" +
                              info.m_skillID.ToString() + "-" + ((int)info.m_skillStepType).ToString() + "-" + info.m_animName + ".anim";
            string        assetPath = path + filename;
            AnimationClip clip      = AssetDatabase.LoadMainAssetAtPath(assetPath) as AnimationClip;
            if (clip != null)
            {
                parentAnim.AddClip(clip, item);
            }
            else
            {
                Debug.Log("load clip failed, path:" + assetPath);
            }
        }
        #endregion
        #region//加载模型的脚本和animation
        if (modelObj.GetComponent <AnimationCameraCallback>() == null)
        {
            modelObj.AddComponent <AnimationCameraCallback>();
        }
        if (modelObj.GetComponent <AnimationEffectCallback>() == null)
        {
            modelObj.AddComponent <AnimationEffectCallback>();
        }
        if (modelObj.GetComponent <AnimationEndCallback>() == null)
        {
            modelObj.AddComponent <AnimationEndCallback>();
        }
        if (modelObj.GetComponent <AnimationShaderParamCallback>() == null)
        {
            modelObj.AddComponent <AnimationShaderParamCallback>();
        }
        if (modelObj.GetComponent <AnimationSoundCallback>() == null)
        {
            modelObj.AddComponent <AnimationSoundCallback>();
        }
        if (modelObj.GetComponent <BreakPointCallback>() == null)
        {
            modelObj.AddComponent <BreakPointCallback>();
        }
        if (modelObj.GetComponent <AttackActionCallback>() == null)
        {
            modelObj.AddComponent <AttackActionCallback>();
        }
        if (LoadAnimationClip(modelObj, modelInfo.modelType, (int)weaponInfo.WeaponType))
        {
            Animation modelAnim = modelObj.GetComponent <Animation>();
            //加载模型的事件
            foreach (var item in m_skillAnimList)
            {
                Info.AnimInfo info = null;
                m_currentInfo.m_animMap.TryGetValue(item, out info);
                AnimationClip copyClip = modelAnim.GetClip(GetFullAnimName(info.m_animName, m_currentInfo.m_modelType, m_currentInfo.m_weaponType));
                if (copyClip == null)
                {
                    Debug.LogError("body get animation failed, anim:" + info.m_animName);
                }
                modelAnim.AddClip(copyClip, item);
                AnimationClip modelClip = modelAnim.GetClip(item);

                AnimationClip parentClip = parentAnim.GetClip(item);
                if (parentClip != null)
                {//从parentObj中获取事件信息
                    AnimationClipCurveData[] array = AnimationUtility.GetAllCurves(parentClip);
                    foreach (var data in array)
                    {
                        if (!m_typeList.Contains(data.type.BaseType))
                        {
                            continue;
                        }
                        string dataPath = "";
                        if (data.path.Contains("body"))
                        {
                            dataPath = data.path.Substring(4);
                        }
                        else if (data.path.Contains("body/"))
                        {
                            dataPath = data.path.Substring(5);
                        }
                        modelClip.SetCurve(dataPath, data.type, data.propertyName, data.curve);
                    }
                    AnimationUtility.SetAnimationEvents(modelClip, AnimationUtility.GetAnimationEvents(parentClip));
                }
                else
                {//获取原来的事件信息,存储在resources/skillanim目录下
                    string dir      = "assets/resources/skillanim/";
                    string animName = "a-" + m_currentInfo.m_modelType.ToString() + "-w" +
                                      m_currentInfo.m_weaponType.ToString() + "-" + info.m_animName + ".anim";
                    UnityEngine.Object tempObj = AssetDatabase.LoadMainAssetAtPath(dir + animName);
                    if (tempObj == null)
                    {
                        //Debug.LogWarning("animation name:" + animName);
                        //resources/skillanim目录下不存在
                        //从原动作中获取
                        AnimationClip bodyClip = modelAnim.GetClip(info.m_animName);
                        if (bodyClip == null)
                        {
                            Debug.LogError("animation is null, name:" + info.m_animName);
                        }
                        else
                        {
                            AnimationClipCurveData[] array = AnimationUtility.GetAllCurves(bodyClip);
                            foreach (var data in array)
                            {
                                if (!m_typeList.Contains(data.type.BaseType))
                                {
                                    continue;
                                }
                                //if (!string.IsNullOrEmpty(data.path))
                                //{//不是body下的
                                //    continue;
                                //}
                                modelClip.SetCurve(data.path, data.type, data.propertyName, data.curve);
                            }
                            AnimationUtility.SetAnimationEvents(modelClip, AnimationUtility.GetAnimationEvents(bodyClip));
                        }
                    }
                    else
                    {
                        AnimationClip            clip  = GameObject.Instantiate(tempObj) as AnimationClip;
                        AnimationClipCurveData[] array = AnimationUtility.GetAllCurves(clip);
                        foreach (var data in array)
                        {
                            if (!m_typeList.Contains(data.type.BaseType))
                            {
                                continue;
                            }
                            //if (!string.IsNullOrEmpty(data.path))
                            //{//不是body下的
                            //    continue;
                            //}
                            modelClip.SetCurve(data.path, data.type, data.propertyName, data.curve);
                        }
                        AnimationUtility.SetAnimationEvents(modelClip, AnimationUtility.GetAnimationEvents(clip));

                        GameObject.DestroyImmediate(clip);
                    }
                }
            }
        }
        else
        {
            Debug.LogError("LoadAnimationClip failed");
        }
        #endregion
        #region//加载武器
        if (weaponInfo.LeftModelID != 0)
        {
            Transform leftArmParentTrans = Actor.S_LookupBone2(modelObj.transform, weaponInfo.LeftPoint);
            ArmLoad(leftArmParentTrans, weaponInfo.LeftModelID, weaponInfo.IsHideLeftModel);
        }
        if (weaponInfo.RightModelID != 0)
        {
            Transform rightArmParentTrans = Actor.S_LookupBone2(modelObj.transform, weaponInfo.RightPoint);
            ArmLoad(rightArmParentTrans, weaponInfo.RightModelID, weaponInfo.IsHideRightModel);
        }
        #endregion
        #region//刷新动画列表
        Animation AniList = modelObj.GetComponent <Animation>();
        m_loadedAnimationList.Clear();
        foreach (AnimationState state in AniList)
        {
            m_loadedAnimationList.Add(state.name);
        }
        m_loadedAnimationList.AddRange(m_skillAnimList);
        m_playingAniIndex = m_loadedAnimationList.Count - 1;
        ED_SimActorManager.Instance.Clear();
        ED_SimActorManager.Instance.AddActor(m_currentObj);
        #endregion

        Selection.activeObject = modelObj;
    }
Exemplo n.º 5
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;
                }
            }
        }
    }
Exemplo n.º 6
0
    void ShowList(Transform contain)
    {
        m_scrollview_npcscrollview.ResetPosition();
        Transform container = contain;

        if (container != null)
        {
            //if (container.childCount != 0)
            //    return;
            for (int j = showNpcList.Count; j < container.childCount; j++)
            {
                string    itemName  = string.Format("{0:D3}", j);
                Transform itemTrans = container.Find(itemName);
                if (itemTrans != null)
                {
                    itemTrans.gameObject.SetActive(false);
                }
            }
            for (int i = 0; i < showNpcList.Count; i++)
            {
                NPCInfo          info     = showNpcList[i];
                MapNpcScrollItem itemInfo = null;
                GameObject       bigItem  = null;
                string           itemName = string.Format("{0:D3}", i);

                if ((MapScrollItemType)info.type == MapScrollItemType.Small)
                {
                    Transform itemTrans = container.Find(itemName);
                    if (itemTrans != null)
                    {
                        bigItem = itemTrans.gameObject;
                    }
                    else
                    {
                        bigItem   = NGUITools.AddChild(container.gameObject, m_sprite_btn_child.gameObject);
                        itemTrans = bigItem.transform;
                    }
                    bigItem.SetActive(true);
                    if (bigItem != null)
                    {
                        itemInfo = bigItem.GetComponent <MapNpcScrollItem>();
                        if (itemInfo == null)
                        {
                            itemInfo = bigItem.AddComponent <MapNpcScrollItem>();
                        }
                    }
                    bigItem.transform.localPosition = new Vector3(0, (i * -70) - 34, 0);
                }
                if (bigItem != null)
                {
                    bigItem.name = itemName;
                    UIEventListener.Get(bigItem.gameObject).onClick = OnScrollItemClick;
                }
                else
                {
                    Log.Error("bigItem is null");
                }
                if (itemInfo != null)
                {
                    itemInfo.InitInfo(info);
                }
            }
        }
    }
Exemplo n.º 7
0
    private void Start()
    {
        _currentInfo = OverriderNpcInfo == null?NpcListInfo.Infos.RandomElement() : OverriderNpcInfo;

        Spawn();
    }
Exemplo n.º 8
0
    private GameObject InstantiateNPC(RuntimeAnimatorController animation, Vector2 position, NPCInfo info)
    {
        Vector3    pos         = LevelManager.Instance.GetCurrentLevel().GetOfficeLayout().coordinateSystem.getVector3(position);
        GameObject npcInstance = Instantiate(npcTemplate, pos, Quaternion.identity);

        npcInstance.GetComponent <Animator>().runtimeAnimatorController = animation; // set the animator controller
        npcInstance.transform.SetParent(this.transform);                             // npcs should show up as a child of the npc controller
        _npcInstances.Add(npcInstance, info);
        return(npcInstance);
    }
Exemplo n.º 9
0
 // Method to be called to hire an employee.
 // Notifies the npcfactory we have hired the npc.
 // This will also take care of randomly placing the NPC into the level.
 public void HireEmployee(NPCInfo npcInfo)
 {
     // Need to notify the npcfactory so we can't reproduce this npc.
     NPCFactory.Instance.RemoveNPCFromPool(npcInfo);
     AddNPCToScene(npcInfo);
 }
Exemplo n.º 10
0
    IEnumerator MoveAndSpawnNPC(List <Vector3> path, Vector3 pos, string n, Vector3 nextTarget)
    {
        while (swapping)
        {
            yield return(new WaitForEndOfFrame());
        }

        Vector3 lastPos = pos;
        bool    swapped = false;

        //Wait until the path is calculated
        while (!Monitor.TryEnter(path) || path.Count == 0)
        {
            Monitor.Exit(path);
            yield return(new WaitForEndOfFrame());
        }
        NPCInfo temp = npcData[n];

        while (path.Count > 0)
        {
            if (saving)
            {
                temp.x          = lastPos.x;
                temp.y          = lastPos.y;
                temp.z          = lastPos.z;
                temp.spawned    = true;
                temp.pathEnd    = ConvertToVec(path[path.Count - 1]);
                temp.nextTarget = ConvertToVec(nextTarget);
                npcData[n]      = temp;
            }
            lastPos = Vector3.MoveTowards(lastPos, path[0], Time.timeScale * Time.deltaTime * 4f);
            if (lastPos == path[0])
            {
                path.RemoveAt(0);
            }
            if (!sceneSwapped)
            {
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                GameObject go = Instantiate(Resources.Load <GameObject>("Characters/" + n));
                go.name = n;
                NPC npc = go.AddComponent <NPC>();
                npc.CharacterName     = n;
                temp.spawned          = true;
                go.transform.position = lastPos;
                temp.x         = lastPos.x;
                temp.y         = lastPos.y;
                temp.z         = lastPos.z;
                npcData[n]     = temp;
                npc.path       = path;
                npc.nextTarget = nextTarget;
                swapped        = true;
                break;
            }
        }

        Monitor.Exit(path);
        if (!swapped)
        {
            temp.map = Mathf.Abs(temp.map - 1);
            if (temp.map == 1)
            {
                temp.x = -7.5f;
                temp.y = -1.5f;
                temp.z = 0;
            }
            else
            {
                temp.x = 0.5f;
                temp.y = -4.5f;
                temp.z = 0;
            }
            temp.spawned = true;
            npcData[n]   = temp;
            List <Vector3> tempPath = new List <Vector3>();
            pathfinder.InitializePath(new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), nextTarget, temp.map, tempPath);
            yield return(new WaitForEndOfFrame());

            if (!sceneSwapped)
            {
                GameObject go = Instantiate(Resources.Load <GameObject>("Characters/" + n));
                go.transform.position = new Vector3(temp.x, temp.y, temp.z);
                NPC npc = go.AddComponent <NPC>();
                npc.path          = tempPath;
                npc.nextTarget    = new Vector3(-9999, -9999, -9999);
                npc.CharacterName = n;
                go.name           = n;
            }
            else
            {
                StartCoroutine(MoveNPC(tempPath, new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), n));
            }
        }
    }
Exemplo n.º 11
0
    public void SetQueue(int day)
    {
        List <string> queued = new List <string>();

        foreach (string key in npcData.Keys.ToList())
        {
            List <Schedule> temp = new List <Schedule>();
            foreach (Schedule s in npcData[key].locations)
            {
                if ((s.repeating && s.day == (day % 6)) || (!s.repeating && s.day == day))
                {
                    if (s.repeating)
                    {
                        temp.Add(s);
                    }
                    npcQueue.Add(s, s.characterName);
                    queued.Add(s.characterName);
                }
                else
                {
                    temp.Add(s);
                }
            }
            NPCInfo tempInfo = npcData[key];
            tempInfo.locations = temp;
            npcData[key]       = tempInfo;
        }

        List <string> available         = new List <string>();
        float         averageCompletion = 0.0f;
        int           count             = 0;

        foreach (string s in npcData.Keys.ToList())
        {
            count++;
            averageCompletion += npcData[s].percentCompleted;
        }
        averageCompletion /= count;
        if (averageCompletion < 0.8f || gaveHint)
        {
            foreach (string key in npcData.Keys.ToList())
            {
                if (!queued.Contains(key) && HasAvailableQuests(key))
                {
                    available.Add(key);
                }
            }
        }
        else
        {
            NPCInfo BlackData, RedData, WhiteData;
            string  highest;
            gaveHint  = true;
            BlackData = npcData["Black_Robed_Traveler"];
            RedData   = npcData["Red_Robed_Traveler"];
            WhiteData = npcData["White_Robed_Traveler"];
            if (BlackData.affinity >= RedData.affinity)
            {
                if (BlackData.affinity >= WhiteData.affinity)
                {
                    highest = "Black_Robed_Traveler";
                    BlackData.shouldGiveHint = true;
                    GameObject.FindObjectOfType <ShrineManager>().order = true;
                }
                else
                {
                    highest = "White_Robed_Traveler";
                    WhiteData.shouldGiveHint = true;
                    GameObject.FindObjectOfType <ShrineManager>().nature = true;
                }
            }
            else
            {
                if (RedData.affinity >= WhiteData.affinity)
                {
                    highest = "Red_Robed_Traveler";
                    RedData.shouldGiveHint = true;
                    GameObject.FindObjectOfType <ShrineManager>().social = true;
                }
                else
                {
                    highest = "White_Robed_Traveler";
                    WhiteData.shouldGiveHint = true;
                    GameObject.FindObjectOfType <ShrineManager>().nature = true;
                }
            }
            available.Add(highest);
        }

        string sendChar = "";
        int    rand     = UnityEngine.Random.Range(0, available.Count);

        int spawnMinute = Mathf.RoundToInt(UnityEngine.Random.Range(0, 50) / 10) * 10;
        int spawnHour   = UnityEngine.Random.Range(8, 13);

        if (mc.Days < 4 && available.Contains("Bernadette"))
        {
            sendChar = "Bernadette";
        }
        else
        {
            sendChar = available[rand];
        }
        Schedule schedule = new Schedule(false, day, spawnHour, spawnMinute, "", 0, -7.5f, -0.5f, 0, sendChar);

        npcQueue.Add(schedule, sendChar);
        schedule = new Schedule(false, day, spawnHour + 6, spawnMinute, "", 1, 69.5f, -12.5f, 0, sendChar);
        npcQueue.Add(schedule, sendChar);
        available.Remove(sendChar);
        if (available.Count > 0)
        {
            spawnMinute = Mathf.RoundToInt(UnityEngine.Random.Range(0, 50) / 10) * 10;
            spawnHour   = UnityEngine.Random.Range(13, 17);
            rand        = UnityEngine.Random.Range(0, available.Count - 1);
            schedule    = new Schedule(false, day, spawnHour, spawnMinute, "", 0, -6.5f, 0.5f, 0, available[rand]);
            npcQueue.Add(schedule, available[rand]);
            schedule = new Schedule(false, day, spawnHour + 6, spawnMinute, "", 1, 69.5f, -12.5f, 0, available[rand]);
            npcQueue.Add(schedule, available[rand]);
            available.RemoveAt(rand);
        }
    }
Exemplo n.º 12
0
    IEnumerator MoveNPC(List <Vector3> path, Vector3 pos, string n)
    {
        while (swapping)
        {
            yield return(new WaitForEndOfFrame());
        }
        Vector3 lastPos = pos;

        //Wait until the path is calculated
        while (!Monitor.TryEnter(path) || path.Count == 0)
        {
            Monitor.Exit(path);
            yield return(new WaitForEndOfFrame());
        }
        NPCInfo temp = npcData[n];

        while (path.Count > 0)
        {
            if (saving)
            {
                temp.x          = lastPos.x;
                temp.y          = lastPos.y;
                temp.z          = lastPos.z;
                temp.spawned    = true;
                temp.pathEnd    = ConvertToVec(path[path.Count - 1]);
                temp.nextTarget = new Vec3(-9999, -9999, -9999);
                npcData[n]      = temp;
            }
            lastPos = Vector3.MoveTowards(lastPos, path[0], Time.timeScale * Time.deltaTime * 4f);
            if (lastPos == path[0])
            {
                path.RemoveAt(0);
            }
            if (!sceneSwapped)
            {
                yield return(new WaitForEndOfFrame());
            }
            else
            {
                GameObject go = Instantiate(Resources.Load <GameObject>("Characters/" + n));
                go.name = n;
                NPC npc = go.AddComponent <NPC>();
                npc.CharacterName     = n;
                npc.nextTarget        = new Vector3(-9999, -9999, -9999);
                go.transform.position = lastPos;
                npcData[n]            = temp;
                npc.path = path;
                break;
            }
        }
        temp.x = lastPos.x;
        temp.y = lastPos.y;
        temp.z = lastPos.z;
        if (temp.map == 1 && temp.x == 69.5f && temp.y == -12.5f)
        {
            temp.spawned = false;
        }
        else
        {
            temp.spawned = true;
        }

        npcData[n] = temp;
        Monitor.Exit(path);
    }
Exemplo n.º 13
0
 //TODO: these conditions can probably be cleaned up/reordered to be shorter
 void HandleMovement(Schedule s, string n)
 {
     //Player is outside and the NPC is going somewhere outside
     if (s.map == 1 && currentMap == 1)
     {
         if (npcData[n].spawned && npcData[n].map == 1)                  //NPC is already outside
         {
             GameObject npc = GameObject.Find(n);
             pathfinder.InitializePath(npc.transform.position, new Vector3(s.x, s.y, s.z), CurrentMap, npc.GetComponent <NPC>().path);
         }
         else if (npcData[n].spawned && npcData[n].map == 0)             //NPC is inside
         {
             List <Vector3> path = new List <Vector3>();
             pathfinder.InitializePath(new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), new Vector3(0.5f, -4.5f, 0), 0, path);
             StartCoroutine(MoveAndSpawnNPC(path, new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), n, new Vector3(s.x, s.y, s.z)));
         }
         else if (!npcData[n].spawned)                                                            //NPC isn't spawned but is going somewhere outside
         {
             GameObject go = Instantiate(Resources.Load <GameObject>("Characters/" + n));
             go.name = n;
             NPC npc = go.AddComponent <NPC>();
             npc.CharacterName = n;
             npc.nextTarget    = new Vector3(-9999, -9999, -9999);
             NPCInfo temp = npcData[n];
             temp.spawned = true;
             Vector3 spawnPoint = GameObject.Find("NPCSpawnPoint").transform.position;
             pathfinder.InitializePath(spawnPoint, new Vector3(s.x, s.y, s.z), 1, npc.path);
             go.transform.position = spawnPoint;
             temp.x     = spawnPoint.x;
             temp.y     = spawnPoint.y;
             temp.z     = spawnPoint.z;
             temp.map   = currentMap;
             npcData[n] = temp;
         }
         //Player is inside and NPC is going somewhere inside
     }
     else if (s.map == 0 && currentMap == 0)
     {
         if (npcData[n].spawned && npcData[n].map == 0)                  //NPC is already inside
         {
             GameObject npc = GameObject.Find(n);
             pathfinder.InitializePath(npc.transform.position, new Vector3(s.x, s.y, s.z), CurrentMap, npc.GetComponent <NPC>().path);
         }
         else if (npcData[n].spawned && npcData[n].map == 1)             //NPC is outside
         {
             List <Vector3> path = new List <Vector3>();
             pathfinder.InitializePath(new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), new Vector3(-7.5f, -1.5f, 0), 1, path);
             StartCoroutine(MoveAndSpawnNPC(path, new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), n, new Vector3(s.x, s.y, s.z)));
         }
         else if (!npcData[n].spawned)                                          //NPC isn't spwaned but is going somewhere inside
         {
             NPCInfo temp = npcData[n];
             temp.spawned = true;
             temp.x       = 69.5f;
             temp.y       = -12.5f;
             temp.z       = 0;
             npcData[n]   = temp;
             List <Vector3> path = new List <Vector3>();
             pathfinder.InitializePath(new Vector3(69.5f, -12.5f, 0), new Vector3(-7.5f, -1.5f, 0), 1, path);
             StartCoroutine(MoveAndSpawnNPC(path, new Vector3(69.5f, -12.5f, 0), n, new Vector3(s.x, s.y, s.z)));
         }
     }
     else if (s.map == 1 && currentMap == 0)
     {
         if (npcData[n].spawned && npcData[n].map == 1)
         {
             List <Vector3> path = new List <Vector3>();
             pathfinder.InitializePath(new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), new Vector3(s.x, s.y, s.z), 1, path);
             StartCoroutine(MoveNPC(path, new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), n));
         }
         else if (npcData[n].spawned && npcData[n].map == 0)
         {
             GameObject npc = GameObject.Find(n);
             pathfinder.InitializePath(npc.transform.position, new Vector3(0.5f, -4.5f, 0), 0, npc.GetComponent <NPC>().path);
             npc.GetComponent <NPC>().nextTarget = new Vector3(s.x, s.y, s.z);
         }
         else if (!npcData[n].spawned)
         {
             NPCInfo temp = npcData[n];
             temp.spawned = true;
             temp.x       = 69.5f;
             temp.y       = -12.5f;
             temp.z       = 0;
             npcData[n]   = temp;
             List <Vector3> path = new List <Vector3>();
             pathfinder.InitializePath(new Vector3(69.5f, -12.5f, 0), new Vector3(s.x, s.y, s.z), 1, path);
             StartCoroutine(MoveNPC(path, new Vector3(69.5f, -12.5f, 0), n));
         }
     }
     else if (s.map == 0 && currentMap == 1)
     {
         if (npcData[n].spawned && npcData[n].map == 1)
         {
             GameObject npc = GameObject.Find(n);
             pathfinder.InitializePath(npc.transform.position, new Vector3(-7.5f, -1.5f, 0), 1, npc.GetComponent <NPC>().path);
             npc.GetComponent <NPC>().nextTarget = new Vector3(s.x, s.y, s.z);
         }
         else if (npcData[n].spawned && npcData[n].map == 0)
         {
             List <Vector3> path = new List <Vector3>();
             pathfinder.InitializePath(new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), new Vector3(s.x, s.y, s.z), 0, path);
             StartCoroutine(MoveNPC(path, new Vector3(npcData[n].x, npcData[n].y, npcData[n].z), n));
         }
         else if (!npcData[n].spawned)
         {
             GameObject go = Instantiate(Resources.Load <GameObject>("Characters/" + n));
             go.name = n;
             NPC npc = go.AddComponent <NPC>();
             npc.CharacterName = n;
             npc.nextTarget    = new Vector3(s.x, s.y, s.z);
             NPCInfo temp = npcData[n];
             temp.spawned = true;
             Vector3 spawnPoint = GameObject.Find("NPCSpawnPoint").transform.position;
             pathfinder.InitializePath(spawnPoint, new Vector3(-7.5f, -1.5f, 0), 1, npc.GetComponent <NPC>().path);
             npc.GetComponent <NPC>().nextTarget = new Vector3(s.x, s.y, s.z);
             go.transform.position = spawnPoint;
             temp.x     = spawnPoint.x;
             temp.y     = spawnPoint.y;
             temp.z     = spawnPoint.z;
             temp.map   = currentMap;
             npcData[n] = temp;
         }
     }
 }
Exemplo n.º 14
0
Arquivo: Util.cs Projeto: zixela/l2net
        static public int Distance(uint id)
        {
            //this function will lock based on what we are checking distance to
            TargetType type = Util.GetType(id);

            switch (type)
            {
            case TargetType.ERROR:
            case TargetType.NONE:
                return(System.Int32.MaxValue);

            case TargetType.SELF:
                return(0);

            case TargetType.MYPET:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.MYPET1:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet1.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet1.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet1.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.MYPET2:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet2.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet2.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet2.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.MYPET3:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet3.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet3.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet3.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.PLAYER:
                Globals.PlayerLock.EnterReadLock();
                try
                {
                    CharInfo player = Util.GetChar(id);

                    if (player != null)
                    {
                        return((int)System.Math.Sqrt(
                                   System.Math.Pow(player.X - Globals.gamedata.my_char.X, 2) +
                                   System.Math.Pow(player.Y - Globals.gamedata.my_char.Y, 2) +
                                   System.Math.Pow(player.Z - Globals.gamedata.my_char.Z, 2)));
                    }
                }    //unlock
                finally
                {
                    Globals.PlayerLock.ExitReadLock();
                }
                break;

            case TargetType.NPC:
                Globals.NPCLock.EnterReadLock();
                try
                {
                    NPCInfo npc = Util.GetNPC(id);

                    if (npc != null)
                    {
                        return((int)System.Math.Sqrt(
                                   System.Math.Pow(npc.X - Globals.gamedata.my_char.X, 2) +
                                   System.Math.Pow(npc.Y - Globals.gamedata.my_char.Y, 2) +
                                   System.Math.Pow(npc.Z - Globals.gamedata.my_char.Z, 2)));
                    }
                }    //unlock
                finally
                {
                    Globals.NPCLock.ExitReadLock();
                }
                break;

            case TargetType.ITEM:
                Globals.ItemLock.EnterReadLock();
                try
                {
                    ItemInfo item = Util.GetItem(id);

                    if (item != null)
                    {
                        return((int)System.Math.Sqrt(
                                   System.Math.Pow(item.X - Globals.gamedata.my_char.X, 2) +
                                   System.Math.Pow(item.Y - Globals.gamedata.my_char.Y, 2) +
                                   System.Math.Pow(item.Z - Globals.gamedata.my_char.Z, 2)));
                    }
                }    //unlock
                finally
                {
                    Globals.ItemLock.ExitReadLock();
                }
                break;
            }

            return(System.Int32.MaxValue);
        }
Exemplo n.º 15
0
Arquivo: Util.cs Projeto: zixela/l2net
        static public int Distance(uint id, TargetType type)
        {
            //no locks needed... since the calling function has the locks in it
            switch (type)
            {
            case TargetType.ERROR:
            case TargetType.NONE:
                return(System.Int32.MaxValue);

            case TargetType.SELF:
                return(0);

            case TargetType.MYPET:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.MYPET1:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet1.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet1.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet1.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.MYPET2:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet2.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet2.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet2.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.MYPET3:
                return((int)System.Math.Sqrt(
                           System.Math.Pow(Globals.gamedata.my_pet3.X - Globals.gamedata.my_char.X, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet3.Y - Globals.gamedata.my_char.Y, 2) +
                           System.Math.Pow(Globals.gamedata.my_pet3.Z - Globals.gamedata.my_char.Z, 2)));

            case TargetType.PLAYER:
                CharInfo player = Util.GetChar(id);

                if (player != null)
                {
                    return((int)System.Math.Sqrt(
                               System.Math.Pow(player.X - Globals.gamedata.my_char.X, 2) +
                               System.Math.Pow(player.Y - Globals.gamedata.my_char.Y, 2) +
                               System.Math.Pow(player.Z - Globals.gamedata.my_char.Z, 2)));
                }
                break;

            case TargetType.NPC:
                NPCInfo npc = Util.GetNPC(id);

                if (npc != null)
                {
                    return((int)System.Math.Sqrt(
                               System.Math.Pow(npc.X - Globals.gamedata.my_char.X, 2) +
                               System.Math.Pow(npc.Y - Globals.gamedata.my_char.Y, 2) +
                               System.Math.Pow(npc.Z - Globals.gamedata.my_char.Z, 2)));
                }
                break;

            case TargetType.ITEM:
                ItemInfo item = Util.GetItem(id);

                if (item != null)
                {
                    return((int)System.Math.Sqrt(
                               System.Math.Pow(item.X - Globals.gamedata.my_char.X, 2) +
                               System.Math.Pow(item.Y - Globals.gamedata.my_char.Y, 2) +
                               System.Math.Pow(item.Z - Globals.gamedata.my_char.Z, 2)));
                }
                break;
            }

            return(System.Int32.MaxValue);
        }
Exemplo n.º 16
0
        private Dialogue GenerateDialogue(NPCInfo npc, bool isAgeDialogue)
        {
            string sentence;

            StaffMentalState.State nextState;
            string[] choices;
            var      currentState = isAgeDialogue ? npc.MentalState.StaffStateAge : npc.MentalState.StaffStateGender;

            switch (currentState)
            {
            case StaffMentalState.State.NORMAL:
                sentence = npc.Attributes.npcName + " thinks the office is boring. " + GetPronoun(npc, true) +
                           " feels out of place.\n" +
                           "Hire some coworkers with the same demographic to improve their mood.";
                nextState = StaffMentalState.State.ANNOYED;
                choices   = new string[]
                {
                    "OK",
                };
                break;

            case StaffMentalState.State.ANNOYED:
                var similar_annoyed = isAgeDialogue ? "a similar age" : "the same gender";
                sentence = npc.Attributes.npcName + " doesn't know many people here and feels lonely, as there aren't many others with " + similar_annoyed + "." +
                           "Encourage your employees to get to know " + GetPronoun(npc, false).ToLower() +
                           " by hosting a pizza party.";
                nextState = StaffMentalState.State.ABOUT_TO_LEAVE;
                choices   = new string[]
                {
                    "Throw Party ($80)",
                    "Ignore"
                };
                break;

            case StaffMentalState.State.ABOUT_TO_LEAVE:
                var similar = isAgeDialogue ? "a similar age" : "the same gender";
                sentence = npc.Attributes.npcName + " feels excluded by " + GetPronoun(npc, false).ToLower() +
                           " coworkers. You could help " + GetPronoun(npc, false).ToLower() + " feel included by hiring others with " + similar + "." +
                           " Host a team-building event to improve workspace culture.";
                nextState = StaffMentalState.State.READY_TO_LEAVE;
                choices   = new string[]
                {
                    "Host team-building event ($80)",
                    "Ignore"
                };
                break;

            default:
                throw new ArgumentOutOfRangeException("state", npc.MentalState.StaffStateGender, null);
            }

            return(new Dialogue
            {
                Sentences = new Sentence[]
                {
                    new Sentence()
                    {
                        icon = npc.Attributes.headshot,
                        Title = npc.Attributes.npcName,
                        sentenceLine = sentence,
                        sentenceChoices = choices,
                        sentenceChoiceActions = new UnityAction[]
                        {
                            delegate()
                            {
                                Debug.Log("Normal option picked");
                                if (nextState != StaffMentalState.State.ANNOYED)
                                {
                                    GameManager.Instance.changeBalance(-80);
                                }

                                if (isAgeDialogue)
                                {
                                    npc.MentalState.StaffStateAge = nextState;
                                    npc.MentalState.AgeDiversityScore = NormalRecovery;
                                }
                                else
                                {
                                    npc.MentalState.StaffStateGender = nextState;
                                    npc.MentalState.GenderDiversityScore = NormalRecovery;
                                }
                                Debug.Log("Setting state to " + npc.MentalState.StaffStateGender);
                                ProjectManager.Instance.ResumeProject();
                                _currentlyDisplaying = false;
                            },
                            delegate()
                            {
                                Debug.Log("Ignore option picked");
                                if (isAgeDialogue)
                                {
                                    npc.MentalState.StaffStateAge = nextState;
                                    npc.MentalState.AgeDiversityScore = IgnoreRecovery;
                                }
                                else
                                {
                                    npc.MentalState.StaffStateGender = nextState;
                                    npc.MentalState.GenderDiversityScore = IgnoreRecovery;
                                }                                Debug.Log("Setting state to " + npc.MentalState.StaffStateGender);
                                ProjectManager.Instance.ResumeProject();
                                _currentlyDisplaying = false;
                            },
                        },
                    }
                }
            });
        }
Exemplo n.º 17
0
 private async Task MakeNpc(NPCInfo data, IPlayerGrain player)
 {
     var npcGrain = GrainFactory.GetGrain<INPCGrain>(player.GetPrimaryKey().ToString() + "Npc" + data.Id);
     await npcGrain.SetInfo(data, player);
     IRoomGrain room = GrainFactory.GetGrain<IRoomGrain>(player.GetPrimaryKey().ToString() + "Room" + data.StartIn);
     await npcGrain.SetRoomGrain(room);
     await npcGrain.SetPlayerGuid(await player.GetPlayerGuid());
     await player.AddNpc(npcGrain);
 }
Exemplo n.º 18
0
    private NPCInfo.npcState lastState; // Last stored State

    public override void OnAwake()
    {
        // Cache Variables
        info      = npcInfo.GetValue() as NPCInfo;
        lastState = info.currentState;
    }
Exemplo n.º 19
0
 public ActionResult <bool> DialogueNPC(NPCInfo npcInfo)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 20
0
        private void UpdateInterface()
        {
            if (NPCInfoListBox.Items.Count != Envir.NPCInfoList.Count)
            {
                NPCInfoListBox.Items.Clear();

                for (int i = 0; i < Envir.NPCInfoList.Count; i++)
                {
                    NPCInfoListBox.Items.Add(Envir.NPCInfoList[i]);
                }
            }

            _selectedNPCInfos = NPCInfoListBox.SelectedItems.Cast <NPCInfo>().ToList();

            if (_selectedNPCInfos.Count == 0)
            {
                NPCInfoPanel.Enabled     = false;
                NPCIndexTextBox.Text     = string.Empty;
                NFileNameTextBox.Text    = string.Empty;
                NNameTextBox.Text        = string.Empty;
                NXTextBox.Text           = string.Empty;
                NYTextBox.Text           = string.Empty;
                NImageTextBox.Text       = string.Empty;
                NRateTextBox.Text        = string.Empty;
                MapComboBox.SelectedItem = null;
                return;
            }

            NPCInfo info = _selectedNPCInfos[0];

            NPCInfoPanel.Enabled = true;

            NPCIndexTextBox.Text     = info.Index.ToString();
            NFileNameTextBox.Text    = info.FileName;
            NNameTextBox.Text        = info.Name;
            NXTextBox.Text           = info.Location.X.ToString();
            NYTextBox.Text           = info.Location.Y.ToString();
            NImageTextBox.Text       = info.Image.ToString();
            NRateTextBox.Text        = info.Rate.ToString();
            MapComboBox.SelectedItem = Envir.MapInfoList.FirstOrDefault(x => x.Index == info.MapIndex);

            for (int i = 1; i < _selectedNPCInfos.Count; i++)
            {
                info = _selectedNPCInfos[i];

                if (NFileNameTextBox.Text != info.FileName)
                {
                    NFileNameTextBox.Text = string.Empty;
                }
                if (NNameTextBox.Text != info.Name)
                {
                    NNameTextBox.Text = string.Empty;
                }
                if (NXTextBox.Text != info.Location.X.ToString())
                {
                    NXTextBox.Text = string.Empty;
                }

                if (NYTextBox.Text != info.Location.Y.ToString())
                {
                    NYTextBox.Text = string.Empty;
                }
                if (NImageTextBox.Text != info.Image.ToString())
                {
                    NImageTextBox.Text = string.Empty;
                }
                if (NRateTextBox.Text != info.Rate.ToString())
                {
                    NRateTextBox.Text = string.Empty;
                }
            }
        }
Exemplo n.º 21
0
    /// <summary>
    /// called when the player hits space (either to enter dialogue, skip text, or see next line)
    /// </summary>
    /// <param name="player"></param>
    /// <param name="npc"></param>
    public void Speak(GameObject player, GameObject npc)
    {
        this.player = player;                                      //set player

        this.npc = npc;                                            //set actor/npc
        if (npcSpeech == null || pInfo == null || npcInfo == null) //get components if they are null (meaning this is the first line)
        {
            npcSpeech = npc.GetComponent <NPCSpeechHolder>();
            pInfo     = player.GetComponent <PlayerInfo>();
            npcInfo   = npc.GetComponent <NPCInfo>();
        }

        //return if we are in the shop
        //useful for if we want to have the merchant talk after buying and selling
        if (inShop)
        {
            return;
        }
        //if not in shop, then we are either in a choice or we are in normal dialogue
        //either way, we need the speechOutline active
        speechOutline.gameObject.SetActive(true);

        //if we are in a choice, return so we don't mess anything up
        if (inChoice)
        {
            return;
        }
        //if in normal dialogue, that means we need the current line to push out
        NPCSpeechHolder.Dialogue dialogue = npcSpeech.Speak();

        //checks to see if the first line of dialogue has been spoken
        if (!hasStartedTalking)
        {
            hasStartedTalking = true;
            player.GetComponent <PlayerMovementScript>().CanPlayerMove = false; //disable player movement
            DoDialogue(dialogue);                                               //prints dialogue
        }
        else if (!hasFinishedTalking)                                           //we havent finished dialogue, so finish it
        {
            hasFinishedTalking = true;
            FinishSpeech(); //print full text
        }
        else                //this means that the current dialogue is done and we can move onto the next line
        {
            hasFinishedTalking = false;
            //checks to see if the current dialogue does not open a shop
            //if it does, this wont run and the shop will open from this line

            if (dialogue.checkQuestCondition)
            {
                changedQuestDialoguePath = true;
                if (CheckQuest(dialogue))
                {
                    npcSpeech.SetDialogueSetChoice(dialogue.setToGoToForComplete);
                }
                else
                {
                    npcSpeech.SetDialogueSetChoice(dialogue.setToGoToForInProgress);
                }
            }
            else
            {
                changedQuestDialoguePath = false;
            }

            GiveQuest(dialogue);
            if (!CheckShop(dialogue))
            {
                //check to see if we can continue talking (reached the last line) and move current dialogue to next one
                bool IsFinished = npcSpeech.UpdateCurrentLine();
                dialogue = npcSpeech.Speak();                //get next line
                if (!IsFinished || changedQuestDialoguePath) //if not finished, print next line
                {
                    DoDialogue(dialogue);
                }
                else     //if we are finished, end the dialogue
                {
                    EndSpeech();
                }
            }
        }
    }
Exemplo n.º 22
0
 void Start()
 {
     info           = GetComponent <NPCInfo>();
     spriteRenderer = GetComponentInChildren <SpriteRenderer>();
     defaultColor   = spriteRenderer.color;
 }
Exemplo n.º 23
0
    public List <NPCData> CollectCurrentData()
    {
        foreach (GameObject c in allNPCsInScene)
        {
            if (c.tag.ToString() != "NPC")
            {
                continue;
            }

            NPCData         temp = new NPCData();
            NPCInfo         a    = c.GetComponent <NPCInfo>();
            Stats           s    = c.GetComponent <Stats>();
            NPCSpeechHolder h    = c.GetComponent <NPCSpeechHolder>();
            CombatScript    cs   = c.GetComponent <CombatScript>();

            temp.x         = c.transform.position.x;
            temp.y         = c.transform.position.y;
            temp.direction = (int)a.direction;
            temp.state     = (int)a.state;

            temp.id       = a.id;
            temp.active   = c.gameObject.activeSelf;
            temp.canMove  = a.canMove;
            temp.inCombat = a.inCombat;
            if (cs.selectedSpell != null)
            {
                temp.selectedSpellID = cs.selectedSpell.ID;
            }
            else
            {
                temp.selectedSpellID = -1;
            }
            temp.castProgress   = cs.ProgressI;
            temp.combatState    = (int)cs.state;
            temp.energyState    = (int)cs.energyState;
            temp.currentHealth  = a.currentHealth;
            temp.currentStamina = a.currentStamina;
            temp.merchantMoney  = a.merchantMoney;
            temp.combatCooldown = a.combatCooldown;
            temp.cooldown       = a.timeStoppedCombat;
            temp.intuition      = s.intuition;
            temp.intelligence   = s.intelligence;
            temp.strength       = s.strength;
            temp.charisma       = s.charisma;
            temp.precision      = s.precision;
            temp.dexterity      = s.dexterity;
            temp.perception     = s.perception;
            temp.attitude       = s.attitude;
            temp.fear           = s.fear;
            temp.danger         = s.danger;
            temp.spirituality   = s.spirituality;
            temp.currentLine    = h.currentLine;
            temp.currentSet     = h.currentSet;
            temp.moveType       = (int)a.movementType;
            temp.areaPointX     = a.destination.x;
            temp.areaPointY     = a.destination.y;
            temp.isWaiting      = a.isWaiting;
            temp.isMoving       = a.isMoving;
            if (a.patrolPoints.Count > 0)
            {
                temp.hasPatrol    = true;
                temp.patrolPointX = a.patrolPoints[0].transform.position.x;
                temp.patrolPointY = a.patrolPoints[0].transform.position.y;
            }
            else
            {
                temp.hasPatrol    = false;
                temp.patrolPointX = 0;
                temp.patrolPointY = 0;
            }

            temp.inventory = new List <InventorySlotData>();
            foreach (Inventory.InventorySlot invSlot in a.merchantInventory.inventory)
            {
                InventorySlotData invSlotData = new InventorySlotData();
                invSlotData.id    = invSlot.item.ID;
                invSlotData.count = invSlot.count;
                temp.inventory.Add(invSlotData);
            }

            temp.maxSize = a.merchantInventory.maxSize;

            AddToData(temp);
        }
        return(allNPCData);
    }
Exemplo n.º 24
0
    IEnumerator OnTalk()
    {
        while (1 > 0)
        {
            yield return(new WaitForSeconds(0.02f));

            if (NPCTalkPanel.Instance.IsClickFinshQuest)
            {
                NPCTalkContentPanel.Instance.ShowContent(NPCinfo.Name, "多谢了!");
                if (FinishQuestuiList.Count <= 1)
                {
                    IsFinishQuest = false;
                }
                QuestManager.Instance.AddCanDeleteQuestList(FinishQuestuiList[FinishQuestuiList.Count - 1]);
                QuestPanel.Instance.UpdateQuestShow();
                FinishQuestuiList.Remove(FinishQuestuiList[FinishQuestuiList.Count - 1]);
                HideFinishIcon();
                break;
            }

            else if (NPCTalkPanel.Instance.IsClickDoquest)
            {
                if (IsStartNPC == true)//跑腿任务 发起人
                {
                    NPCTalkContentPanel.Instance.ShowContent(NPCinfo.Name, "去找" + NPCManager.Instance.GetNPCByID(NPCTaklQuest[NPCTaklQuest.Count - 1].Quest.NPCID).Name);
                    if (NPCTaklQuest.Count <= 1)
                    {
                        IsStartNPC = false;
                    }
                    QuestManager.Instance.AddStartQuestList(NPCTaklQuest[NPCTaklQuest.Count - 1]);
                    NPCTaklQuest.Remove(NPCTaklQuest[NPCTaklQuest.Count - 1]);
                    HideQuestIcon();
                }
                switch (NPCQuestuis[NPCQuestuis.Count - 1].Quest.Questtype)
                {
                case Quest.QuestType.Combat:
                    NPCTalkContentPanel.Instance.ShowContent(NPCinfo.Name, "杀敌数不够!!");
                    break;

                case Quest.QuestType.Talk:
                    NPCInfo startnPCInfo = NPCManager.Instance.GetNPCByID(NPCQuestuis[NPCQuestuis.Count - 1].Quest.StartNPCID);
                    NPCTalkContentPanel.Instance.ShowContent(NPCinfo.Name, "哦 我知道了。\n 你回去告诉" + startnPCInfo.Name + "吧。");
                    if (NPCQuestuis.Count <= 1)
                    {
                        IsQuestTarget = false;
                    }
                    HideQuestIcon();
                    QuestManager.Instance.AddFinishQuestList(NPCQuestuis[NPCQuestuis.Count - 1]);
                    NPCQuestuis.Remove(NPCQuestuis[NPCQuestuis.Count - 1]);
                    break;

                case Quest.QuestType.GetItem:
                    NPCTalkContentPanel.Instance.ShowContent(NPCinfo.Name, "物品数量不够!!");
                    break;

                case Quest.QuestType.Work:
                    break;
                }
                break;
            }
            else if (NPCTalkPanel.Instance.IsClickAcceptQuest)
            {
                QuestAcceptPanel.Instance.Show();
                break;
            }
            else if (NPCTalkPanel.Instance.IsClickBusiness)
            {
                ShopPanel.Instance.Show();
                break;
            }
            else if (NPCTalkPanel.Instance.IsClickTalk)
            {
                int randomnum = Random.Range(0, NPCinfo.TalkText.Count);
                NPCTalkContentPanel.Instance.ShowContent(NPCinfo.Name, NPCinfo.TalkText[randomnum]);
                break;
            }
            else if (NPCTalkPanel.Instance.IsClickQuit)
            {
                break;
            }
        }
    }
Exemplo n.º 25
0
 public override void OnAwake()
 {
     info = npcInfo.GetValue() as NPCInfo;
 }
Exemplo n.º 26
0
 public override void SetAll(System.Collections.Generic.IDictionary<string,object> values)
 {   
     object value;
     if (values == null) { InitStateFields(); return; }
     if (values.TryGetValue("roomGrain", out value)) roomGrain = (IRoomGrain) value;
     if (values.TryGetValue("playerGuid", out value)) playerGuid = (Guid) value;
     if (values.TryGetValue("playerGrain", out value)) playerGrain = (IPlayerGrain) value;
     if (values.TryGetValue("npcInfo", out value)) npcInfo = (NPCInfo) value;
 }
Exemplo n.º 27
0
        private void UpdateInterface()
        {
            if (NPCInfoListBox.Items.Count != Envir.NPCInfoList.Count)
            {
                NPCInfoListBox.Items.Clear();

                for (int i = 0; i < Envir.NPCInfoList.Count; i++)
                {
                    NPCInfoListBox.Items.Add(Envir.NPCInfoList[i]);
                }
            }

            _selectedNPCInfos = NPCInfoListBox.SelectedItems.Cast <NPCInfo>().ToList();

            if (_selectedNPCInfos.Count == 0)
            {
                tabPage1.Enabled                   = false;
                tabPage2.Enabled                   = false;
                NPCIndexTextBox.Text               = string.Empty;
                NFileNameTextBox.Text              = string.Empty;
                NNameTextBox.Text                  = string.Empty;
                NXTextBox.Text                     = string.Empty;
                NYTextBox.Text                     = string.Empty;
                NImageTextBox.Text                 = string.Empty;
                NRateTextBox.Text                  = string.Empty;
                MapComboBox.SelectedItem           = null;
                MinLev_textbox.Text                = string.Empty;
                MaxLev_textbox.Text                = string.Empty;
                Class_combo.Text                   = string.Empty;
                ConquestHidden_combo.SelectedIndex = -1;
                Day_combo.Text                     = string.Empty;
                TimeVisible_checkbox.Checked       = false;
                StartHour_combo.Text               = string.Empty;
                EndHour_combo.Text                 = string.Empty;
                StartMin_num.Value                 = 0;
                EndMin_num.Value                   = 1;
                Flag_textbox.Text                  = string.Empty;
                return;
            }

            NPCInfo info = _selectedNPCInfos[0];

            tabPage1.Enabled = true;
            tabPage2.Enabled = true;

            NPCIndexTextBox.Text              = info.Index.ToString();
            NFileNameTextBox.Text             = info.FileName;
            NNameTextBox.Text                 = info.Name;
            NXTextBox.Text                    = info.Location.X.ToString();
            NYTextBox.Text                    = info.Location.Y.ToString();
            NImageTextBox.Text                = info.Image.ToString();
            NRateTextBox.Text                 = info.Rate.ToString();
            MapComboBox.SelectedItem          = Envir.MapInfoList.FirstOrDefault(x => x.Index == info.MapIndex);
            MinLev_textbox.Text               = info.MinLev.ToString();
            MaxLev_textbox.Text               = info.MaxLev.ToString();
            Class_combo.Text                  = info.ClassRequired;
            ConquestHidden_combo.SelectedItem = Envir.ConquestInfos.FirstOrDefault(x => x.Index == info.Conquest);
            Day_combo.Text                    = info.DayofWeek;
            TimeVisible_checkbox.Checked      = info.TimeVisible;
            StartHour_combo.Text              = info.HourStart.ToString();
            EndHour_combo.Text                = info.HourEnd.ToString();
            StartMin_num.Value                = info.MinuteStart;
            EndMin_num.Value                  = info.MinuteEnd;
            Flag_textbox.Text                 = info.FlagNeeded.ToString();


            for (int i = 1; i < _selectedNPCInfos.Count; i++)
            {
                info = _selectedNPCInfos[i];

                if (NFileNameTextBox.Text != info.FileName)
                {
                    NFileNameTextBox.Text = string.Empty;
                }
                if (NNameTextBox.Text != info.Name)
                {
                    NNameTextBox.Text = string.Empty;
                }
                if (NXTextBox.Text != info.Location.X.ToString())
                {
                    NXTextBox.Text = string.Empty;
                }

                if (NYTextBox.Text != info.Location.Y.ToString())
                {
                    NYTextBox.Text = string.Empty;
                }
                if (NImageTextBox.Text != info.Image.ToString())
                {
                    NImageTextBox.Text = string.Empty;
                }
                if (NRateTextBox.Text != info.Rate.ToString())
                {
                    NRateTextBox.Text = string.Empty;
                }
            }
        }
Exemplo n.º 28
0
 private void InitStateFields()
 {
     this.roomGrain = default(IRoomGrain);
     this.playerGuid = default(Guid);
     this.playerGrain = default(IPlayerGrain);
     this.npcInfo = new NPCInfo();
 }
Exemplo n.º 29
0
 public override void OnAwake()
 {
     // Cache Variables
     info = npcInfo.GetValue() as NPCInfo;
 }
Exemplo n.º 30
0
 private void LoadNPCs()
 {
     try
     {
     //What if it didn't contain a db.xml?
     //What if it didn't contain an NPC or Category element??
         //NPCList =
         var NPCs =_dbXml.Root.Element("npc").Descendants("category").Elements()
                   .Select(item => new { key = item.Name, xpath= item.GetAbsoluteXPath(), value = item.Element("name").Value });
         NPCList = new Dictionary<string,NPCInfo>();
         foreach (var npc in NPCs)
         {
             var npcInfo = new NPCInfo(npc.value.ToString(), npc.xpath.ToString());
             NPCList.Add(npc.key.ToString(),npcInfo);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 31
0
        private void LoadClientMap(string mapPath)
        {
            m_dicNpcInfo.Clear();
            m_dicZones.Clear();
            if (string.IsNullOrEmpty(mapPath))
            {
                return;
            }

            try
            {
                byte[] bytes = Engine.Utility.FileUtils.Instance().ReadFile(mapPath);
                if (bytes == null)
                {
                    return;
                }
                string          xml    = System.Text.Encoding.UTF8.GetString(bytes);
                SecurityElement seRoot = XmlParser.Parser(xml);
                if (seRoot != null)
                {
                    SecurityElement npcse = seRoot.SearchForChildByTag("Npc");
                    if (npcse != null)
                    {
                        if (npcse.Children != null)
                        {
                            for (int i = 0; i < npcse.Children.Count; i++)
                            {
                                SecurityElement item = (SecurityElement)npcse.Children[i];
                                NPCInfo         info = new NPCInfo();
                                info.npcID = int.Parse(item.Attribute("id"));
                                float x = float.Parse(item.Attribute("x"));
                                if (!string.IsNullOrEmpty(item.Attribute("tx")))
                                {
                                    x = float.Parse(item.Attribute("tx"));
                                }
                                float z = float.Parse(item.Attribute("y"));
                                if (!string.IsNullOrEmpty(item.Attribute("ty")))
                                {
                                    z = float.Parse(item.Attribute("ty"));
                                }
                                bool bShow = true;
                                if (!string.IsNullOrEmpty(item.Attribute("visible")))
                                {
                                    int n = int.Parse(item.Attribute("visible"));
                                    bShow = n == 1 ? true : false;
                                }
                                info.name  = item.Attribute("name");
                                info.pos   = new Vector2(x, z);
                                info.bShow = bShow;
                                List <NPCInfo> lstInfo = null;
                                if (!m_dicNpcInfo.TryGetValue(info.npcID, out lstInfo))
                                {
                                    lstInfo = new List <NPCInfo>();

                                    m_dicNpcInfo.Add(info.npcID, lstInfo);
                                }

                                if (lstInfo != null)
                                {
                                    lstInfo.Add(info);
                                }
                            }
                        }
                    }
                    //副本区域
                    SecurityElement zonese = seRoot.SearchForChildByTag("Zone");
                    if (zonese != null && zonese.Children != null)
                    {
                        for (int i = 0; i < npcse.Children.Count; i++)
                        {
                            SecurityElement item   = (SecurityElement)npcse.Children[i];
                            int             id     = int.Parse(item.Attribute("id"));
                            int             width  = int.Parse(item.Attribute("width"));
                            int             height = int.Parse(item.Attribute("height"));
                            int             x      = int.Parse(item.Attribute("x"));
                            int             y      = int.Parse(item.Attribute("y"));
                            if (!m_dicZones.ContainsKey(id))
                            {
                                m_dicZones.Add(id, new Rect(x, y, width, height));
                            }
                        }
                    }
                }
                bytes = null;
                Engine.Utility.Log.Trace("LoadXmlNPC:" + m_dicNpcInfo.Count);
            }
            catch (Exception e)
            {
                Engine.Utility.Log.Error(e.ToString());
            }
        }
Exemplo n.º 32
0
        static public void GetLoc(uint id, ref int x, ref int y, ref int z)
        {
            //is self?
            if (Globals.gamedata.my_char.ID == id)
            {
                x = Float_Int32(Globals.gamedata.my_char.X);
                y = Float_Int32(Globals.gamedata.my_char.Y);
                z = Float_Int32(Globals.gamedata.my_char.Z);
                return;
            }

            //is my pet?
            if (Globals.gamedata.my_pet.ID == id)
            {
                x = Float_Int32(Globals.gamedata.my_pet.X);
                y = Float_Int32(Globals.gamedata.my_pet.Y);
                z = Float_Int32(Globals.gamedata.my_pet.Z);
                return;
            }
            if (Globals.gamedata.my_pet1.ID == id)
            {
                x = Float_Int32(Globals.gamedata.my_pet1.X);
                y = Float_Int32(Globals.gamedata.my_pet1.Y);
                z = Float_Int32(Globals.gamedata.my_pet1.Z);
                return;
            }
            if (Globals.gamedata.my_pet2.ID == id)
            {
                x = Float_Int32(Globals.gamedata.my_pet2.X);
                y = Float_Int32(Globals.gamedata.my_pet2.Y);
                z = Float_Int32(Globals.gamedata.my_pet2.Z);
                return;
            }
            if (Globals.gamedata.my_pet3.ID == id)
            {
                x = Float_Int32(Globals.gamedata.my_pet3.X);
                y = Float_Int32(Globals.gamedata.my_pet3.Y);
                z = Float_Int32(Globals.gamedata.my_pet3.Z);
                return;
            }

            //is in the list of chars?
            Globals.PlayerLock.EnterReadLock();
            try
            {
                CharInfo player = GetChar(id);

                if (player != null)
                {
                    x = Float_Int32(player.X);
                    y = Float_Int32(player.Y);
                    z = Float_Int32(player.Z);
                    return;
                }
            }
            finally
            {
                Globals.PlayerLock.ExitReadLock();
            }

            //is it a party member?
            Globals.PartyLock.EnterReadLock();
            try
            {
                PartyMember pmem = GetCharParty(id);

                if (pmem != null)
                {
                    x = pmem.X;
                    y = pmem.Y;
                    z = pmem.Z;
                    return;
                }
            }
            finally
            {
                Globals.PartyLock.ExitReadLock();
            }

            Globals.NPCLock.EnterReadLock();
            try
            {
                NPCInfo npc = GetNPC(id);

                if (npc != null)
                {
                    x = Float_Int32(npc.X);
                    y = Float_Int32(npc.Y);
                    z = Float_Int32(npc.Z);
                    return;
                }
            }
            finally
            {
                Globals.NPCLock.ExitReadLock();
            }
        }