예제 #1
0
 internal void CheckCellRemove(NPCCell cell)
 {
     if (cell.NPCCount == 0)
     {
         npcCells.Remove(cell.Coord);
     }
 }
예제 #2
0
        internal void UpdateNPCCell(NPC npc, Vec3f pos)
        {
            if (npc == null)
            {
                throw new ArgumentNullException("NPC is null!");
            }

            Vec2i coords = NPCCell.GetCoords(pos);

            if (coords.X != npc.NpcCell.X || coords.Y != npc.NpcCell.Y)
            {
                npc.NpcCell.RemoveNPC(npc);
                CheckCellRemove(npc.NpcCell);

                int     coord = NPCCell.GetCoordinate(coords.X, coords.Y);
                NPCCell cell;
                if (!npcCells.TryGetValue(coord, out cell))
                {
                    cell = new NPCCell(this, coords.X, coords.Y);
                    npcCells.Add(coord, cell);
                }
                cell.AddNPC(npc);
                npc.NpcCell = cell;
            }
        }
예제 #3
0
 /// <summary>
 /// 是否跟随玩家
 /// </summary>
 public void AIFollowPlayer()
 {
     for (int i = 0; i < allNpc.Count; i++)
     {
         NPCCell tmpCell = allNpc[i];
         tmpCell.AIAttack();
     }
 }
예제 #4
0
    /// <summary>
    /// 工厂模式 生成一个NPC
    /// </summary>
    /// <param name="path">NPC资源路径</param>
    /// <param name="NPCParent">NPC位置父类</param>
    /// <returns></returns>
    public GameObject FactoryNPC(string path, Transform NPCParent)
    {
        Object     tmpOBJ = Resources.Load(path);
        GameObject tmpNPC = GameObject.Instantiate(tmpOBJ) as GameObject;

        tmpNPC.transform.SetParent(NPCParent, false);
        NPCCell tmpCell = tmpNPC.AddComponent <NPCCell>();

        allNpc.Add(tmpCell);
        return(tmpNPC);
    }
예제 #5
0
 /// <summary>
 /// 玩家放大招 NPC检测受伤
 /// </summary>
 public void AttackByPlayer()
 {
     for (int i = 0; i < allNpc.Count; i++)
     {
         NPCCell tmpCell = allNpc[i];
         if (IsRectAttack(Player, tmpCell.transform, npcManagerModle.ForwardDistance, npcManagerModle.RightDistance))
         {
             tmpCell.ReduceBlood(npcManagerModle.ReduceDistance);
         }
     }
 }
예제 #6
0
    public void   RegistGameObject(GameObject tmpObj, NPCCell tmpBase)
    {
        //  if (!SonMembers.ContainsKey(npcCount))
        {
            tmpBase.player = Player;
            tmpBase.Index  = npcCount;


            SonMembers.Add(tmpBase);

            //SonMembers.Add(npcCount, tmpBase);

            npcCount++;
        }
    }
예제 #7
0
        internal void AddToNPCCells(NPC npc)
        {
            // find the cell for this npc
            Vec2i   coords = NPCCell.GetCoords(npc.Position);
            int     coord  = NPCCell.GetCoordinate(coords.X, coords.Y);
            NPCCell cell;

            if (!npcCells.TryGetValue(coord, out cell))
            {
                cell = new NPCCell(this, coords.X, coords.Y);
                npcCells.Add(coord, cell);
            }
            cell.AddNPC(npc);
            npc.NpcCell = cell;
        }
예제 #8
0
        /// <summary>
        /// 1000 ingame units accuracy
        /// </summary>
        public void ForEachNPCRoughPredicate(Vec3f pos, float radius, Predicate <NPC> predicate)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException("Predicate is null!");
            }

            Vec2i min = NPCCell.GetCoords(new Vec3f(pos.X - radius, pos.Y, pos.Z - radius));
            Vec2i max = NPCCell.GetCoords(new Vec3f(pos.X + radius, pos.Y, pos.Z + radius));

            for (int x = min.X; x <= max.X; x++)
            {
                for (int y = min.Y; y <= max.Y; y++)
                {
                    if (npcCells.TryGetValue(NPCCell.GetCoordinate(x, y), out NPCCell cell))
                    {
                        cell.ForEachNPCPredicate(predicate);
                    }
                }
            }
        }
예제 #9
0
        /// <summary>
        /// 1000 ingame units accuracy
        /// </summary>
        public void ForEachNPCRough(Vec3f pos, float radius, Action <NPC> action)
        {
            if (action == null)
            {
                throw new ArgumentNullException("Action is null!");
            }

            Vec2i min = NPCCell.GetCoords(new Vec3f(pos.X - radius, pos.Y, pos.Z - radius));
            Vec2i max = NPCCell.GetCoords(new Vec3f(pos.X + radius, pos.Y, pos.Z + radius));

            for (int x = min.X; x <= max.X; x++)
            {
                for (int y = min.Y; y <= max.Y; y++)
                {
                    NPCCell cell;
                    if (npcCells.TryGetValue(NPCCell.GetCoordinate(x, y), out cell))
                    {
                        cell.ForEachNPC(action);
                    }
                }
            }
        }