Beispiel #1
0
 // EDITOR FUNCTIONS
 public void SetPatrolParams(List <Vector3> _waypoints, PatrolData _checkPatrol = new PatrolData(), bool _loop = false)
 {
     waypoints.Clear();
     waypoints.AddRange(_waypoints);
     checkPatrol = _checkPatrol;
     loop        = _loop;
 }
 public override void Start()
 {
     EventManager.PatrolSwitchChange += SwitchDiection;
     this.data      = this.gameobject.GetComponent <PatrolData>();
     this.direction = (targetSide)Random.Range(0, 4);
     this.target    = this.getTarget(this.direction);
 }
        private void ml_form_garrison_detachment_consequence(MenuCallbackArgs args, PatrolData dat)
        {
            List <InquiryElement> inq = MenuUtils.AssemblePatrolSizes(dat);

            InformationManager.ShowMultiSelectionInquiry(new MultiSelectionInquiryData(new TextObject("{=ml.patrol.size.select}Select Size").ToString(), new TextObject("{=ml.patrol.size.select.desc}Select the size of the patrol you want.").ToString(), inq, true, 1, "Name and purchase", "Cancel",
                                                                                       delegate(List <InquiryElement> selection)
            {
                if (selection != null)
                {
                    if (selection.Count != 0)
                    {
                        InformationManager.ShowTextInquiry(new TextInquiryData(new TextObject("{=ml.name.patrol}Select your patrol's name: ", null).ToString(), string.Empty, true, false, GameTexts.FindText("str_done", null).ToString(), null,
                                                                               delegate(string str)
                        {
                            TownPatrolData newPatrol = SpawnTownPatrol(str, selection[0].Title.ToLower(), dat, true);
                            this._mlTownPatrols[Settlement.CurrentSettlement.StringId].Add(newPatrol);
                            InformationManager.HideInquiry();
                        }, null, false, null, "", Settlement.CurrentSettlement.Name.ToString() + " " + dat.name));
                    }
                }
            },
                                                                                       delegate(List <InquiryElement> selection)
            {
                InformationManager.HideInquiry();
            }));
        }
 public override void Start()
 {
     // this.gameobject.GetComponent<Animator>().SetBool("run", true);
     data            = this.gameobject.GetComponent <PatrolData>();
     sceneController = SSDirector.GetInstance().currentSceneController as FirstController;
     enable          = true;
 }
Beispiel #5
0
        // all of this is really really bad but idc
        public static List <InquiryElement> AssemblePatrolSizes(PatrolData dat)
        {
            MBObjectManager       objManager = Game.Current.ObjectManager;
            List <InquiryElement> list       = new List <InquiryElement>();

            CharacterObject ch1 = objManager.GetObject <CharacterObject>("looter");
            CharacterObject ch2 = objManager.GetObject <CharacterObject>("imperial_recruit");
            CharacterObject ch3 = objManager.GetObject <CharacterObject>("imperial_infantryman");
            CharacterObject ch4 = objManager.GetObject <CharacterObject>("imperial_veteran_infantryman");

            if (dat.sizes.Contains("small"))
            {
                list.Add(new InquiryElement(dat, "Small " + "(" + dat.basePrice.ToString() + " gold)", new ImageIdentifier(CharacterCode.CreateFrom(ch1))));
            }
            if (dat.sizes.Contains("medium"))
            {
                if (Hero.MainHero.Gold >= dat.basePrice + dat.priceStep)
                {
                    list.Add(new InquiryElement(dat, "Medium " + "(" + (dat.basePrice + dat.priceStep).ToString() + " gold)", new ImageIdentifier(CharacterCode.CreateFrom(ch2))));
                }
                else
                {
                    list.Add(new InquiryElement(dat, "Medium " + "(" + (dat.basePrice + dat.priceStep).ToString() + " gold)", new ImageIdentifier(CharacterCode.CreateFrom(ch2)), false, "You do not have enough gold to purchase this size"));
                }
            }
            if (dat.sizes.Contains("large"))
            {
                if (Hero.MainHero.Gold >= dat.basePrice + (dat.priceStep * 2))
                {
                    list.Add(new InquiryElement(dat, "Large " + "(" + (dat.basePrice + (dat.priceStep * 2)).ToString() + " gold)", new ImageIdentifier(CharacterCode.CreateFrom(ch3))));
                }
                else
                {
                    list.Add(new InquiryElement(dat, "Large " + "(" + (dat.basePrice + (dat.priceStep * 2)).ToString() + " gold)", new ImageIdentifier(CharacterCode.CreateFrom(ch3)), false, "You do not have enough gold to purchase this size"));
                }
            }
            if (dat.sizes.Contains("huge"))
            {
                if (Hero.MainHero.Gold >= dat.basePrice + (dat.priceStep * 3))
                {
                    list.Add(new InquiryElement(dat, "Large " + "(" + (dat.basePrice + (dat.priceStep * 3)).ToString() + " gold)", new ImageIdentifier(CharacterCode.CreateFrom(ch4))));
                }
                else
                {
                    list.Add(new InquiryElement(dat, "Large " + "(" + (dat.basePrice + (dat.priceStep * 3)).ToString() + " gold)", new ImageIdentifier(CharacterCode.CreateFrom(ch4)), false, "You do not have enough gold to purchase this size"));
                }
            }

            if (list.Count == 0)
            {
                throw new Exception("Assembling sizes of patrol {" + dat.templateName + "} failed");
            }
            else
            {
                return(list);
            }
        }
Beispiel #6
0
    private void OnEnable()
    {
        source    = (PatrolData)target;
        sourceRef = serializedObject;

        SceneView.duringSceneGui += OnSceneGUI;

        GetProperties();
    }
Beispiel #7
0
 public void makePatrol(int num)
 {
     for (no = 0; no < num; no++)
     {
         PatrolData temp = new PatrolData(no);
         temp.location = position[no];
         temp.show();
         patrols.Add(temp);
     }
 }
Beispiel #8
0
    public GameObject AddEnemyOfficer(Vector3 startPos, List <Vector3> waypoints, PatrolData patrolData, Quaternion rotation)
    {
        var instance = InstanceOfficer(startPos, waypoints, patrolData);

        if (instance != null)
        {
            instance.transform.rotation = rotation;
        }

        return(instance);
    }
Beispiel #9
0
 private GameObject InstanceOfficer(Vector3 startPos, List <Vector3> waypoints, PatrolData patrolData = new PatrolData())
 {
     if (InputParamsValid(startPos, waypoints, patrolData))
     {
         var officer = Instantiate(enemyOfficerPref, startPos, Quaternion.identity);
         officer.GetComponent <EnemyManager>().Initialize();
         officer.GetComponent <EnemyMover_Officer>().SetPatrolParams(waypoints, patrolData);
         return(officer);
     }
     return(null);
 }
Beispiel #10
0
 // Use this for initialization
 public override void Start()
 {
     sceneController = (myGameObject)SSDirector.getInstance().currentSceneController;
     if (this.gameobject != null)
     {
         patrol = sceneController.patrol.getPatrol(this.transform.name);
     }
     dis    = patrol.location;
     player = sceneController.player.player;
     this.gameobject.GetComponent <Animation>().Play();
 }
    public static void SaveFile(string file_name)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(Application.persistentDataPath + "/" + file_name + ".dat");

        PatrolData data = ScriptableObject.CreateInstance <PatrolData>();

        data.static_patrol = true;

        bf.Serialize(file, data);
        file.Close();
    }
Beispiel #12
0
    public Dictionary <Vector3, int> LoadEnemyXml(Dictionary <Vector3, Dictionary <Vector3, PatrolData> > patrplData)
    {
        Dictionary <Vector3, int> mapIndexObj = new Dictionary <Vector3, int>();
        //创建xml文档
        XmlDocument       xml = new XmlDocument();
        XmlReaderSettings set = new XmlReaderSettings();

        set.IgnoreComments = true;//这个设置是忽略xml注释文档的影响。有时候注释会影响到xml的读取
        xml.Load(XmlReader.Create((Application.dataPath + "/StreamingAssets/enemy.xml"), set));

        //得到objects节点下的所有子节点
        XmlNodeList xmlNodeList = xml.SelectSingleNode("Map").ChildNodes;

        //遍历所有子节点
        foreach (XmlElement xl1 in xmlNodeList)
        {
            if (xl1.Name == "enemy")
            {
                string[] itemlist = xl1.InnerXml.Split('=');
                for (int i = 0; i < itemlist.Length - 1; i++)
                {
                    string[] list = itemlist[i].Split(',');
                    mapIndexObj[new Vector3(int.Parse(list[0]), int.Parse(list[1]), int.Parse(list[2]))] = int.Parse(list[3]);

                    if (list[4] != "null")
                    {
                        patrplData[new Vector3(int.Parse(list[0]), int.Parse(list[1]), int.Parse(list[2]))] = new Dictionary <Vector3, PatrolData>();
                        Dictionary <Vector3, PatrolData> patrollist = patrplData[new Vector3(int.Parse(list[0]), int.Parse(list[1]), int.Parse(list[2]))];
                        string[] alist = list[4].Split('a');
                        for (int j = 0; j < alist.Length - 1; j++)
                        {
                            string[] blist = alist[j].Split('b');
                            Vector3  v3    = new Vector3(int.Parse(blist[0]), int.Parse(blist[1]), int.Parse(blist[2]));
                            if (blist[3] == "null")
                            {
                                patrollist[v3] = null;
                            }
                            else
                            {
                                patrollist[v3] = new PatrolData();
                                string[] clist = blist[3].Split('c');
                                patrollist[v3].stayTime = int.Parse(clist[0]);
                                patrollist[v3].agentmin = int.Parse(clist[1]);
                                patrollist[v3].agentmax = int.Parse(clist[2]);
                                patrollist[v3].loop     = int.Parse(clist[3]);
                            }
                        }
                    }
                }
            }
        }
        return(mapIndexObj);
    }
    public static void LoadFile(string file_name)
    {
        if (File.Exists(Application.persistentDataPath + "/" + file_name + ".dat"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/" + file_name + ".dat", FileMode.Open);
            PatrolData      p    = (PatrolData)bf.Deserialize(file);
            Debug.Log(p.static_patrol);

            file.Close();
        }
    }
Beispiel #14
0
 public void freePatrol(GameObject oldPatrol)
 {
     for (int i = 0; i < used.Count; i++)
     {
         if (used [i].gameObject == oldPatrol)
         {
             PatrolData move = used[i];
             used.Remove(move);
             free.Add(move);
             return;
         }
     }
     Debug.Log("Exception: No such disk int used list");
 }
    public static void LoadXML(string file_name)
    {
        float test = 50;

        Debug.Log(Application.persistentDataPath);

        // Stream the file with a File Stream. (Note that File.Create() 'Creates' or 'Overwrites' a file.)
        //FileStream file = File.Open(Application.persistentDataPath + "/" + file_name + ".dat", FileMode.Open);
        // Create a new Player_Data.
        PatrolData data = new PatrolData(5);

        //Serialize to xml
        DataContractSerializer bf       = new DataContractSerializer(data.GetType());
        MemoryStream           streamer = new MemoryStream();

        //file_name = Path.Combine(this.path, Application.persistentDataPath, file_name + ".dat");

        //DataContractSerializer dcs = new DataContractSerializer(typeof(Games));
        FileStream          fs     = new FileStream(Application.persistentDataPath + "/" + file_name + ".xml", FileMode.Open);
        XmlDictionaryReader reader = XmlDictionaryReader.CreateTextReader(fs, new XmlDictionaryReaderQuotas());

        data = (PatrolData)bf.ReadObject(reader);
        reader.Close();
        fs.Close();


        ////Serialize the file
        //data = (PatrolData)bf.ReadObject(streamer);

        //Debug.Log(data.is_synchronized);
        //Debug.Log(data.synchronized_Rhandor);
        //Debug.Log(data.give_permission_pos);
        //Debug.Log(data.path[0]);

        //bf.WriteObject(streamer, data);
        //streamer.Seek(0, SeekOrigin.Begin);

        //Save to disk
        //file.Write(streamer.GetBuffer(), 0, streamer.GetBuffer().Length);

        // Close the file to prevent any corruptions
        //file.Close();

        //string result = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer()).Replace("\0", "")).ToString();
        //Debug.Log("Serialized Result: " + result);
    }
Beispiel #16
0
    private bool InputParamsValid(Vector3 startPos, List <Vector3> waypoints, PatrolData patrolData)
    {
        bool startposValid = false;

        // bool checkPatrolPositionValid = false;

        for (int i = 0; i < waypoints.Count - 1; i++)
        {
            if (waypoints[i].x == waypoints[i + 1].x)
            {
                if (startPos.x == waypoints[i].x)
                {
                    startposValid = true;
                }
                // if (patrolData.Position.x == waypoints[i].x) checkPatrolPositionValid = true;
            }
            else if (waypoints[i].z == waypoints[i + 1].z)
            {
                if (startPos.z == waypoints[i].z)
                {
                    startposValid = true;
                }
                // if (patrolData.Position.z == waypoints[i].z) checkPatrolPositionValid = true;
            }
            else
            {
                Debug.Log("Not valid patrol path");
                return(false);
            }

            if (waypoints[i] == waypoints[i + 1])
            {
                Debug.Log("Not valid patrol path");
                return(false);
            }
        }

        if (!startposValid)
        {
            Debug.Log("Start position is not valid");
            return(false);
        }

        return(true);
    }
        private static TownPatrolData SpawnTownPatrol(string name, string size, PatrolData dat, bool isPlayerSpawn, Settlement spawnSettlement = null)
        {
            MBObjectManager objManager = Game.Current.ObjectManager;
            TextObject      pName      = new TextObject(name);

            PartyTemplateObject templateObject = (PartyTemplateObject)objManager.GetObject <PartyTemplateObject>(dat.templateName + "_" + size);

            spawnSettlement = isPlayerSpawn ? Settlement.CurrentSettlement : spawnSettlement;

            MobileParty patrol = objManager.CreateObject <MobileParty>(dat.templateName + "_" + size + "_" + 1);

            patrol.InitializeMobileParty(MenuUtils.ConstructTroopRoster(templateObject, patrol.Party), new TroopRoster(patrol.Party), isPlayerSpawn ? Settlement.CurrentSettlement.GatePosition : spawnSettlement.GatePosition, 0);

            patrol.SetCustomName(pName);
            patrol.Party.Owner = spawnSettlement.MapFaction.Leader == null?spawnSettlement.OwnerClan.Heroes.ToList().First() : spawnSettlement.OwnerClan.Leader;

            patrol.Party.Visuals.SetMapIconAsDirty();
            patrol.ActualClan     = spawnSettlement.OwnerClan;
            patrol.HomeSettlement = spawnSettlement;
            MenuUtils.CreatePartyTrade(patrol);

            foreach (ItemObject obj in ItemObject.All)
            {
                if (obj.IsFood)
                {
                    int num = MBRandom.RandomInt(patrol.MemberRoster.TotalManCount / 3, patrol.MemberRoster.TotalManCount);
                    if (num > 0)
                    {
                        patrol.ItemRoster.AddToCounts(obj, num);
                    }
                }
            }

            patrol.SetMovePatrolAroundSettlement(spawnSettlement);

            return(new TownPatrolData(pName.ToString(), size, patrol));
        }
    public static void SaveXML(string file_name)
    {
        float test = 50;

        Debug.Log(Application.persistentDataPath);

        // Stream the file with a File Stream. (Note that File.Create() 'Creates' or 'Overwrites' a file.)
        FileStream file = File.Create(Application.persistentDataPath + "/" + file_name + ".xml");
        // Create a new Player_Data.
        PatrolData data = ScriptableObject.CreateInstance <PatrolData>();

        //Save the data.
        data.is_synchronized     = true;
        data.path_attached       = GameObject.Find("Neutral_trigger");
        data.give_permission_pos = 15;
        data.path[0]             = Vector3.forward;

        //Serialize to xml
        DataContractSerializer bf       = new DataContractSerializer(data.GetType());
        MemoryStream           streamer = new MemoryStream();

        //Serialize the file
        bf.WriteObject(streamer, data);
        streamer.Seek(0, SeekOrigin.Begin);

        //Save to disk
        file.Write(streamer.GetBuffer(), 0, streamer.GetBuffer().Length);

        // Close the file to prevent any corruptions
        file.Close();

        //string result = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer()).Replace("\0", "")).ToString();
        string result = XElement.Parse(Encoding.ASCII.GetString(streamer.GetBuffer())).ToString();

        Debug.Log("Serialized Result: " + result);
    }
Beispiel #19
0
    private bool PatrolDataIsValid(List <Vector3> waypoints, PatrolData patrolData)
    {
        bool checkPatrolPositionValid = false;

        for (int i = 0; i < waypoints.Count - 1; i++)
        {
            if (waypoints[i].x == waypoints[i + 1].x)
            {
                if (patrolData.Position.x == waypoints[i].x)
                {
                    checkPatrolPositionValid = true;
                }
            }
            else if (waypoints[i].z == waypoints[i + 1].z)
            {
                if (patrolData.Position.z == waypoints[i].z)
                {
                    checkPatrolPositionValid = true;
                }
            }
        }

        return(checkPatrolPositionValid);
    }
Beispiel #20
0
    public void MoveNpc(int spawnTriggerId, string patrolDataName)
    {
        PatrolData patrolData = MapEntityMetadataStorage.GetPatrolData(Field.MapId, patrolDataName);

        Field.State.Npcs.Values.FirstOrDefault(x => x.SpawnPointId == spawnTriggerId)?.SetPatrolData(patrolData);
    }
Beispiel #21
0
 public override void Start()
 {
     this.gameobject.GetComponent <Animator>().SetBool("run", true);
     data = this.gameobject.GetComponent <PatrolData>();
 }
Beispiel #22
0
 public override void Start()
 {
     data = this.gameObject.GetComponent <PatrolData>();
 }
Beispiel #23
0
 public override void Start()
 {
     info = this.gameObject.GetComponent <PatrolData>();
     this.gameObject.GetComponent <Animator>().SetBool("track", true);
 }
Beispiel #24
0
 public void SetOfficerPatrolData(GameObject officer, PatrolData patrolData) =>
 officer.GetComponent <EnemyMover_Officer>().SetPatrolParams(patrolData);
Beispiel #25
0
 public override void Start()
 {
     this.enable = true;
     patrolData  = this.gameobject.GetComponent <PatrolData> ();
 }
Beispiel #26
0
 public override void Start()
 {
     this.gameobject.GetComponent <Animator>().SetBool("walk", true);
     PatrolData  = this.gameobject.GetComponent <PatrolData>();
     this.enable = true;
 }
Beispiel #27
0
    private void updataPatrol()
    {
        if (patrolPositionList == null || patrolPositionList.Count == 0)
        {
            return;
        }

        if (curPatrolData != null)
        {
            if (resetAgent == false)
            {
                if (transform.eulerAngles.y - curPatrolData.agentmin > 180)
                {
                    transform.Rotate(new Vector3(0, 3, 0));
                }
                else
                {
                    transform.Rotate(new Vector3(0, -3, 0));
                }
                if (Math.Abs(transform.eulerAngles.y - curPatrolData.agentmin) < 10)
                {
                    resetAgent = true;
                }
                return;
            }
            else
            {
                if (curloop > curPatrolData.loop)
                {
                }
                else
                {
                    if (curloop % 2 == 0)
                    {
                        transform.Rotate(new Vector3(0, (curPatrolData.agentmax - curPatrolData.agentmin) / curPatrolData.stayTime, 0));
                        if (Math.Abs(transform.eulerAngles.y - curPatrolData.agentmax) < Math.Abs((curPatrolData.agentmax - curPatrolData.agentmin) / curPatrolData.stayTime))
                        {
                            curloop++;
                        }
                    }
                    else
                    {
                        transform.Rotate(new Vector3(0, (curPatrolData.agentmin - curPatrolData.agentmax) / curPatrolData.stayTime, 0));
                        if (Math.Abs(transform.eulerAngles.y - curPatrolData.agentmin) < Math.Abs((curPatrolData.agentmax - curPatrolData.agentmin) / curPatrolData.stayTime))
                        {
                            curloop++;
                        }
                    }
                }
            }

            patrolIndex++;
            if (patrolIndex > curPatrolData.stayTime * curPatrolData.loop)
            {
                agent.enabled = true;
                iswalk        = false;
                curPatrolIndex++;
                if (curPatrolIndex >= patrolPositionList.Count)
                {
                    curPatrolIndex = 0;
                }
                curPatrolData = null;
            }
            return;
        }

        if (curPatrolIndex >= 0)
        {
            if (iswalk == false)
            {
                if (Vector3.Distance(patrolPositionList[curPatrolIndex], transform.position) < 1)
                {
                    if (patrolList[curPatrolIndex] == null)
                    {
                        iswalk = false;
                        curPatrolIndex++;
                        if (curPatrolIndex >= patrolPositionList.Count)
                        {
                            curPatrolIndex = 0;
                        }
                    }
                    else
                    {
                        curPatrolData = patrolList[curPatrolIndex];
                        curloop       = patrolIndex = 0;
                        agent.enabled = false;
                        resetAgent    = false;
                    }
                    return;
                }
                else
                {
                    agent.SetDestination(patrolPositionList[curPatrolIndex]);
                    iswalk  = true;
                    jiangge = 0;
                }
            }
            if (jiangge < 20)
            {
                jiangge++;
                return;
            }
            if (Math.Abs(agent.remainingDistance) < 0.02 && agent.enabled && agent.pathStatus == NavMeshPathStatus.PathComplete)
            {
                if (patrolList[curPatrolIndex] == null)
                {
                    iswalk = false;
                    curPatrolIndex++;
                    if (curPatrolIndex >= patrolPositionList.Count)
                    {
                        curPatrolIndex = 0;
                    }
                }
                else
                {
                    curPatrolData = patrolList[curPatrolIndex];
                    curloop       = patrolIndex = 0;
                    agent.enabled = false;
                    resetAgent    = false;
                    //iswalk = false;
                    //curPatrolIndex++;
                    //if (curPatrolIndex >= patrolPositionList.Count)
                    //{
                    //    curPatrolIndex = 0;
                    //}
                }
            }
        }
    }
Beispiel #28
0
 public void SetPatrolParams(PatrolData _checkPatrol) =>
 checkPatrol = _checkPatrol;
    public void MoveUserPath(string movePath)
    {
        PatrolData patrolData = MapEntityMetadataStorage.GetPatrolData(Field.MapId, movePath);

        Field.MovePlayerAlongPath(Field.State.Players.First().Value, patrolData);
    }
 public void MoveNpc(int spawnTriggerId, string patrolDataName)
 {
     PatrolData patrolData = MapEntityStorage.GetPatrolData(Field.MapId, patrolDataName);
 }