示例#1
0
 public static void ReadRange(BinaryReader _reader, out PeCustom.RANGE obj)
 {
     ReadVector3(_reader, out obj.center);
     ReadVector3(_reader, out obj.extend);
     obj.radius  = _reader.ReadSingle();
     obj.type    = (PeCustom.RANGE.RANGETYPE)_reader.ReadByte();
     obj.inverse = _reader.ReadBoolean();
 }
示例#2
0
 public static void Serialize(BinaryWriter writer, PeCustom.RANGE obj)
 {
     Serialize(writer, obj.center);
     Serialize(writer, obj.extend);
     Serialize(writer, obj.radius);
     Serialize(writer, (byte)obj.type);
     Serialize(writer, obj.inverse);
 }
示例#3
0
        public static string ToString_RANGE(RANGE range)
        {
            string formatstr = "";

            switch (range.type)
            {
            case RANGE.RANGETYPE.Anywhere:
                return(range.inverse ? "0" : "-1");

            case RANGE.RANGETYPE.Box:
                if (range.inverse)
                {
                    formatstr = "B':{0},{1},{2}:{3},{4},{5}";
                }
                else
                {
                    formatstr = "B:{0},{1},{2}:{3},{4},{5}";
                }
                return(string.Format(formatstr,
                                     range.center.x, range.center.y, range.center.z,
                                     range.extend.x, range.extend.y, range.extend.z));

            case RANGE.RANGETYPE.Sphere:
                if (range.inverse)
                {
                    formatstr = "S':{0},{1},{2}:{3}";
                }
                else
                {
                    formatstr = "S:{0},{1},{2}:{3}";
                }
                return(string.Format(formatstr, range.center.x, range.center.y, range.center.z, range.radius));

            case RANGE.RANGETYPE.Circle:
                if (range.inverse)
                {
                    formatstr = "C':{0},{1},{2}:{3}";
                }
                else
                {
                    formatstr = "C:{0},{1},{2}:{3}";
                }
                return(string.Format(formatstr, range.center.x, range.center.y, range.center.z, range.radius));
            }
            return("0");
        }
 // 在此初始化参数
 protected override void OnCreate()
 {
     obj   = Utility.ToObject(parameters["object"]);
     range = Utility.ToRange(missionVars, parameters["range"]);
 }
示例#5
0
        /// <summary>
        /// 删除指定范围内Object
        /// </summary>
        /// <param name="proto">Object类型</param>
        /// <param name="range">删除范围</param>
        /// <returns></returns>
        public static bool RemoveObjects(OBJECT proto, RANGE range)
        {
            if (!proto.isPrototype)
            {
                return(false);
            }

            if (proto.isAnyPrototype)
            {
                SpawnDataSource data = PeCustomScene.Self.spawnData;

                if (proto.type == OBJECT.OBJECTTYPE.MonsterProto)
                {
                    // Monster point
                    _tempSPList.Clear();
                    foreach (var kvp in data.monsters)
                    {
                        if (range.Contains(kvp.Value.entityPos))
                        {
                            _tempSPList.Add(kvp.Value);
                        }
                    }

                    for (int i = 0; i < _tempSPList.Count; i++)
                    {
                        PeCustomScene.Self.RemoveSpawnPoint(_tempSPList[i]);
                    }
                    _tempSPList.Clear();

                    // Monster area
                    foreach (var kvp in data.areas)
                    {
                        for (int i = 0; i < kvp.Value.Spawns.Count; i++)
                        {
                            for (int j = 0; j < kvp.Value.Spawns[i].spawnPoints.Count; j++)
                            {
                                MonsterSpawnPoint msp = kvp.Value.Spawns[i].spawnPoints[j];
                                if (range.Contains(msp.entityPos))
                                {
                                    if (msp.EntityID != -1)
                                    {
                                        CreatureMgr.Instance.Destory(msp.EntityID);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (proto.type == OBJECT.OBJECTTYPE.ItemProto)
                {
                    List <ISceneObjAgent> agents = SceneMan.GetSceneObjs <DragItemAgent>();
                    for (int i = 0; i < agents.Count; i++)
                    {
                        DragItemAgent drag_agent = agents[i] as DragItemAgent;
                        if (range.Contains(drag_agent.position))
                        {
                            DragItemAgent.Destory(drag_agent);
                        }
                    }
                }
            }
            else
            {
                SpawnDataSource data = PeCustomScene.Self.spawnData;
                if (proto.type == OBJECT.OBJECTTYPE.MonsterProto)
                {
                    // Monster point
                    _tempSPList.Clear();
                    foreach (var kvp in data.monsters)
                    {
                        if (kvp.Value.Prototype == proto.Id && range.Contains(kvp.Value.entityPos))
                        {
                            _tempSPList.Add(kvp.Value);
                        }
                    }

                    for (int i = 0; i < _tempSPList.Count; i++)
                    {
                        PeCustomScene.Self.RemoveSpawnPoint(_tempSPList[i]);
                    }
                    _tempSPList.Clear();

                    // Monster area
                    foreach (var kvp in data.areas)
                    {
                        for (int i = 0; i < kvp.Value.Spawns.Count; i++)
                        {
                            for (int j = 0; j < kvp.Value.Spawns[i].spawnPoints.Count; j++)
                            {
                                MonsterSpawnPoint msp = kvp.Value.Spawns[i].spawnPoints[j];
                                if (kvp.Value.Prototype == proto.Id && range.Contains(msp.entityPos))
                                {
                                    if (msp.EntityID != -1)
                                    {
                                        CreatureMgr.Instance.Destory(msp.EntityID);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (proto.type == OBJECT.OBJECTTYPE.ItemProto)
                {
                    List <ISceneObjAgent> agents = SceneMan.GetSceneObjs <DragArticleAgent>();
                    for (int i = 0; i < agents.Count; i++)
                    {
                        DragArticleAgent drag_agent = agents[i] as DragArticleAgent;
                        if (drag_agent.itemDrag.itemObj.protoId == proto.Id && range.Contains(drag_agent.position))
                        {
                            DragItemAgent.Destory(drag_agent);
                        }
                    }
                }
            }

            return(true);
        }
示例#6
0
        /// <summary>
        /// 在一定范围创建指定数量的Object
        /// </summary>
        /// <param name="amout">创建Object数量</param>
        /// <param name="proto">Object 类型</param>
        /// <param name="range">创建范围</param>
        /// <returns></returns>
        public static bool CreateObjects(int amout, OBJECT proto, RANGE range)
        {
            if (range.type == RANGE.RANGETYPE.Anywhere || range.type == RANGE.RANGETYPE.Circle)
            {
                return(false);
            }

            if (!proto.isSpecificPrototype)
            {
                return(false);
            }

            int            min_sqr_dis = 5;
            List <Vector3> spawn_pos   = new List <Vector3>(10);

            if (range.type == RANGE.RANGETYPE.Sphere)
            {
                float raduis = range.radius;
                for (int i = 0; i < amout; i++)
                {
                    int     n     = 0;
                    int     index = -1;
                    Vector3 pos   = Vector3.zero;
                    do
                    {
                        pos = range.center + (Random.insideUnitSphere * raduis * 2
                                              - new Vector3(raduis, raduis, raduis));

                        index = spawn_pos.FindIndex(item0 => (pos - item0).sqrMagnitude < min_sqr_dis);
                        n++;
                    }while (index != -1 && n < 30);

                    spawn_pos.Add(pos);

                    // Create
                    CreateObject(proto, pos);

                    if (n >= 30)
                    {
                        break;
                    }
                }
            }
            else if (range.type == RANGE.RANGETYPE.Box)
            {
                Vector3 extent = new Vector3(range.extend.x, range.extend.y, range.extend.z);
                for (int i = 0; i < amout; i++)
                {
                    int     n     = 0;
                    int     index = -1;
                    Vector3 pos   = Vector3.zero;
                    do
                    {
                        pos = range.center + (new Vector3(Random.value * extent.x,
                                                          Random.value * extent.y, Random.value * extent.z) * 2 - extent);

                        index = spawn_pos.FindIndex(item0 => (pos - item0).sqrMagnitude < min_sqr_dis);
                        n++;
                    }while (index != -1 && n < 30);

                    spawn_pos.Add(pos);

                    // Create
                    CreateObject(proto, pos);

                    if (n >= 30)
                    {
                        break;
                    }
                }
            }

            return(true);
        }
示例#7
0
        public static bool TryParse_RANGE(string s, out RANGE range)
        {
            if (s == "0")
            {
                range = RANGE.nowhere;
                return(true);
            }
            else if (s == "-1")
            {
                range = RANGE.anywhere;
                return(true);
            }
            else
            {
                range = RANGE.anywhere;
                string[] ss = s.Split(new string[1] {
                    ":"
                }, StringSplitOptions.None);
                if (ss.Length != 3)
                {
                    return(false);
                }
                ss[0] = ss[0];
                if (ss[0] == "B" || ss[0] == "B'")
                {
                    range.type = RANGE.RANGETYPE.Box;
                    if (ss[0].Length == 1)
                    {
                        range.inverse = false;
                    }
                    else
                    {
                        range.inverse = true;
                    }

                    if (!TryParse_VECTOR(ss[1], out range.center))
                    {
                        return(false);
                    }
                    if (!TryParse_VECTOR(ss[2], out range.extend))
                    {
                        return(false);
                    }
                    return(true);
                }
                else if (ss[0] == "S" || ss[0] == "S'")
                {
                    range.type = RANGE.RANGETYPE.Sphere;
                    if (ss[0].Length == 1)
                    {
                        range.inverse = false;
                    }
                    else
                    {
                        range.inverse = true;
                    }

                    if (!TryParse_VECTOR(ss[1], out range.center))
                    {
                        return(false);
                    }
                    if (!float.TryParse(ss[2], floatStyle, NumberFormatInfo.CurrentInfo, out range.radius))
                    {
                        return(false);
                    }
                    return(true);
                }
                else if (ss[0] == "C" || ss[0] == "C'")
                {
                    range.type = RANGE.RANGETYPE.Circle;
                    if (ss[0].Length == 1)
                    {
                        range.inverse = false;
                    }
                    else
                    {
                        range.inverse = true;
                    }

                    if (!TryParse_VECTOR(ss[1], out range.center))
                    {
                        return(false);
                    }
                    if (!float.TryParse(ss[2], floatStyle, NumberFormatInfo.CurrentInfo, out range.radius))
                    {
                        return(false);
                    }
                    return(true);
                }
                return(false);
            }
        }