public List <NpcAccessPoint> GetDestinationsForNpcType(NpcType type, NpcAccessPoint excluded) { List <NpcAccessPoint> compatibleAPs = new List <NpcAccessPoint>(); foreach (var ap in _accessPoints) { if (ap != null) { // Make sure we are not using destinations from the same ship/planet that the NPC was spawned if (ap.transform.parent != null && excluded != null && excluded.transform.parent != null) { if (ap.transform.parent == excluded.transform.parent) { continue; } } if (ap != excluded && type.IsAccessPointCompatible(ap.type)) { compatibleAPs.Add(ap); } } } return(compatibleAPs); }
/// <summary> /// Creates a new instance of the <see cref="Npc"/> class. /// </summary> public Npc(MmoZone zone, int objectId, short groupId, NpcType npcType, NpcData npcData) : base(zone, ObjectType.Npc, objectId, groupId, new Bounds(), npcData) { this.npcType = npcType; this.alignment = (SocialAlignment)npcData.Alignment; this.lootGroupId = npcData.LootGroupId; this.startableQuestIds = npcData.StartQuests; this.completableQuestIds = npcData.CompleteQuests; this.BuildProperties(Properties, PropertyFlags.NpcAll); this.Revision = this.Properties.Count; if (Properties.Count > 0) { this.Flags |= MmoObjectFlags.HasProperties; } this.SetBaseStat(Stats.Health, (short)npcData.MaxHealth); this.SetHealth(MaximumHealth); this.SetBaseStat(Stats.Power, (short)npcData.MaxMana); this.SetPower(MaximumPower); this.threatTable = new Dictionary <MmoGuid, float>(); this.CurrentAggroState = AggroState.Idle; this.visibleCharacters = new Dictionary <Character, IDisposable>(); this.radarEnterRadius = ServerGameSettings.BASE_AGGRO_RADIUS; this.radarExitRadius = ServerGameSettings.BASE_AGGRO_DROP_RADIUS; this.ai = npcType == NpcType.Enemy ? (NpcAI) new NpcAggressiveAI(this) : new NpcDefensiveAI(this); this.inventory = npcData.Items; }
void Start () { _rb = GetComponent<Rigidbody>(); _npcType = GetComponent<NpcType>(); avoidanceSpeed *= _rb.mass; _forwardSpeed = Random.Range(forwardSpeed.x, forwardSpeed.y) * _rb.mass; }
private void OnLevelWasLoaded(int level) { for (int i = 0; i < type.Length; i++) { drop[i] = new Drop(type[i]); } sel = Random.Range(0, 10); currentDrop = drop[sel]; if (variable && (npcType == NpcType.vendor || npcType == NpcType.common)) { if (Random.Range(0, 2) == 1) { npcType = NpcType.vendor; } else { npcType = NpcType.common; } } if (npcType == NpcType.vendor || npcType == NpcType.seller) { GenerateDialogue(); } npcState = State.idle; }
void Start() { _rb = GetComponent <Rigidbody>(); _npcType = GetComponent <NpcType>(); avoidanceSpeed *= _rb.mass; _forwardSpeed = Random.Range(forwardSpeed.x, forwardSpeed.y) * _rb.mass; }
public static Npc FindNearest(NpcType npcType, Transform transform) { if (npcType == NpcType.FARMER) { FarmerNpc closestFarmer = null; foreach (FarmerNpc farmer in farmers) { if (closestFarmer == null) { closestFarmer = farmer; } else { Vector3 vectorToClosestFarmer = transform.position - closestFarmer.transform.position; Vector3 vectorToFarmer = transform.position - farmer.transform.position; if (vectorToFarmer.magnitude < vectorToClosestFarmer.magnitude) { closestFarmer = farmer; } } } return(closestFarmer); } return(null); }
// Start is called before the first frame update void Start() { player = GameObject.FindGameObjectWithTag("Player").transform.Find("human2a").gameObject; hasInteracted = false; dead = false; npcType = (NpcType)Random.Range(0, (int)NpcType.Count); }
internal List <NPCData> GetNpcDatas(NpcType npcType) { var query = from m in mNpcDatas.Values where m.npcType == npcType select m; return(query.ToList <NPCData>()); }
public NpcDomainBuilder Flee(NpcType type, float refreshInterval = 2f) { Action("Flee from Npc type: " + type); if (Pointer is IPrimitiveTask task) { task.SetOperator(new FleeOperator(type, refreshInterval)); } return(this); }
private void InPositionToDock(AbstractGoTween tween) { OnDestinationReached(); NpcType npcType = GetComponent <NpcType>(); if (npcType != null) { npcType.Dock(_dockedAPType); } }
/// <summary> /// Creates new NPC. /// </summary> public Monster(int id, NpcType type) { this.Handle = ChannelServer.Instance.World.CreateHandle(); this.Id = id; this.NpcType = type; this.Level = 1; this.SDR = 1; this.Hp = this.MaxHp = 100; this.DisappearTime = DateTime.MaxValue; }
public static SpawnNpcPacket Create(uint _id, ushort _mesh, Point _location, NpcType _type = NpcType.Task) { var packet = new SpawnNpcPacket(); packet.UID = _id; packet.X = (ushort)_location.X; packet.Y = (ushort)_location.Y; packet.Mesh = _mesh; packet.Type = _type; return(packet); }
public Npc(string name, int entryId, WowMapId mapId, WowZoneId zoneId, Vector3 position, NpcType type, NpcSubType subType = NpcSubType.None) { Name = name; EntryId = entryId; MapId = mapId; ZoneId = zoneId; Position = position; Type = type; SubType = subType; }
public NpcHolder(int npcId, NpcType npcType, int level, bool sex, long hp, int stamina, int strength, int dexterity, int intelect) { this.npcId = npcId; this.npcType = npcType; this.level = level; this.sex = sex; this.hp = hp; this.stamina = stamina; this.strength = strength; this.dexterity = dexterity; this.intelect = intelect; }
public FollowState(GameObject leader, Ship leaderController, float maxVelocity, NpcType typeToDetect) { this.leader = leader; this.leaderController = leaderController; this.maxVelocity = 30; this.typeToDetect = typeToDetect; npcDetector = new NPCDetector(); stateID = StateID.BotFollowStateID; }
public void Initialize(long id, NpcData proto, FixVector3 p, FixVector3 r) { this.id = id; type = LogicUnitType.NPC; position = p; transform.position = p.vector3; transform.rotation = Quaternion.Euler(r.vector3); brithPosition = p; brithDirection = r; hurtType = AttackPropertyType.PhysicalAttack; npcProto = proto; iconId = -1; metaId = proto.ID; modelId = proto.ModelID; modelRadius = ConvertUtils.ToLogicInt(proto.ModelRadius); npcType = (NpcType)proto.NPCType; attackType = (NpcAttackType)proto.StandardAttack; rebornInterval = ConvertUtils.ToLogicInt(proto.RebornInterval); physicasAttack = (int)proto.PhysicsAttack; armor = (int)proto.Armor; magicResist = (int)proto.MagicResist; speedFactor = ConvertUtils.ToLogicInt(proto.Speed); healthRegen = proto.HealthRegen; maxHp = proto.Health; chaseArea = ConvertUtils.ToLogicInt(proto.TargetDetectRange); maxChaseDistance = ConvertUtils.ToLogicInt(proto.MaxChaseDistance); emberOutPut = proto.EmberOutPut; projectileId = proto.ProjectileId; attackRange = ConvertUtils.ToLogicInt(proto.AttackRange); killReward = proto.KillReward; attackDuration = ConvertUtils.ToLogicInt(proto.AttackDuration); attackHitTime = ConvertUtils.ToLogicInt(proto.AttackHitDuration); fightInterval = 1; hp = maxHp; damage = physicasAttack; healthRecoverInterval = GameConstants.HP_RECOVERY_INTERVAL_MILLISECOND; InitializeState(); InitializePathAgent(); debuffHandler = new DebuffHandler(); buffHandler = new BuffHandler(); state = NpcState.IDLE; currentFsm = fsmIdle; }
//[TestMethod] public void Execute() { IronRubyScript script = new IronRubyScript(); script.Content = @"m=new MoveAction(new MapPoint(0,2,2));"; GameMap game = MapCreation(1000, 1000, 1, 0, 0); NpcType type = new NpcType(); type.Description = "1"; type.Name = "1"; MapActiveObject obj = new MapActiveObject(null, null, new MapSize(1, 1), MapDirection.East, MapArmorType.None, 100, 0); Npc npc = new Npc(type, obj); NpcState state = new NpcState(npc, game.Map, script, new Fraction(), new MapPoint(0, 1, 1)); state.PerformAction(); //npc.Position = game.Map.Levels[0].Cells[1,1]; //Move move = new Move(new MapPoint(0, 1, 2), npc); //((NPCAction)move).perform(game.Map); //MapCreation(1000, 1000, 1, 0, 0); //SimpleObject obj= new SimpleObject(); //obj.mas=new int[50000000]; //Random rand = new Random(); //for (int i = 0; i < obj.mas.Length; i++) // obj.mas[i] = rand.Next(100000); // ScriptRuntime runtime = IronRuby.Ruby.CreateRuntime(); // ScriptEngine _rubyEngine = runtime.GetEngine("Ruby"); // ScriptScope _scope = _rubyEngine.CreateScope(); // _scope.SetVariable("obj", obj); // DateTime time1 = DateTime.Now; // var result1 = _rubyEngine.Execute(@" mas=[] // (0..obj.mas.size()-1).each do |x| // if obj.mas[x]<100 // mas+= [obj.mas[x]] // end // end // m1=mas ", _scope); // DateTime time2 = DateTime.Now; // var result2 = _rubyEngine.Execute(@" obj.mas.find_all{|elem| elem<100} ", _scope); // DateTime time3 = DateTime.Now; // var result3 = _rubyEngine.Execute(@" obj.getless100() ", _scope); // DateTime time4 = DateTime.Now; // var result4 = obj.getless100(); // DateTime time5 = DateTime.Now; // var result5 = obj.mas.Where(x => x < 100).ToArray(); // DateTime time6 = DateTime.Now; }
public NpcHolder(int npcId, NpcType npcType, int level, bool sex, long hp, int stamina, int strength, int dexterity, int intelect) { _npcId = npcId; _npcType = npcType; _level = level; _sex = sex; _hp = hp; _stamina = stamina; _strength = strength; _dexterity = dexterity; _intelect = intelect; }
public void ClearNpcData(NpcType npcType) { var array = GetNpcDatas(npcType); if (array != null && array.Count > 0) { foreach (var de in array) { mNpcDatas.Remove(de.npcid); } } }
public bool ParseNavMeshInfo(string info, NpcType type = NpcType.NT_None) { if (StageMgr.Loading) { return(false); } if (TeamSystem.IsTeamLeader() || !TeamSystem.IsInTeam() || TeamSystem.AwayTeam(GamePlayer.Instance.InstId)) { if (type != NpcType.NT_None) { NetConnection.Instance.moveToNpc2(type); return(true); } if (string.IsNullOrEmpty(info)) { return(false); } // "|" 为scene和zone分隔符 // ";" 为scene和npc分隔符 string[] parse; int sceneId; if (info.Contains("|")) { parse = info.Split('|'); sceneId = int.Parse(parse[0]); int zoneId = int.Parse(parse[1]); NetConnection.Instance.moveToZone(sceneId, zoneId); } else { parse = info.Split(';'); sceneId = int.Parse(parse[0]); int npcId = int.Parse(parse[1]); NpcData npcd = NpcData.GetData(npcId); if (npcd.Type == NpcType.NT_Caiji1 || npcd.Type == NpcType.NT_Caiji2 || npcd.Type == NpcType.NT_Caiji3) { NetConnection.Instance.moveToNpc2(npcd.Type); } else { NetConnection.Instance.moveToNpc(npcId); } //Prebattle.Instance.selectedNpc_ = npcId; } return(true); } return(false); }
// Unsure about how to handle the "DialogType" part of the packet. // When this is wrong, the game is stuck with an invisible dialog. public static Packet Respond(IFieldObject <Npc> npc, NpcType npcType, DialogType dialogType, int scriptId) { PacketWriter pWriter = PacketWriter.Of(SendOp.NPC_TALK); pWriter.WriteByte(0x01); pWriter.WriteInt(npc.ObjectId); pWriter.WriteEnum(npcType); pWriter.WriteInt(scriptId); pWriter.WriteInt(); pWriter.WriteEnum(dialogType); return(pWriter); }
public NPCData NewNpcData(uint roleid, NpcType npcType) { var npcid = MakeNpcId(); var npcData = new NPCData(npcid); npcData.roleid = roleid; npcData.npcType = npcType; var roleData = configMgr.GetRoleData(roleid); npcData.jobType = roleData.job; return(npcData); }
public static PacketWriter Respond(IFieldObject <NpcMetadata> npc, NpcType npcType, DialogType dialogType, int scriptId) { PacketWriter pWriter = PacketWriter.Of(SendOp.NPC_TALK); pWriter.Write(NpcTalkMode.Respond); pWriter.WriteInt(npc.ObjectId); pWriter.Write(npcType); pWriter.WriteInt(scriptId); pWriter.WriteInt(); pWriter.Write(dialogType); return(pWriter); }
public WanderState(GameObject npc, Vector3 velocity, NpcType typeToDetect, float detectrange, Transform gunTipPosition) { this.velocity = npc.transform.forward * MaxSpeed; this.startPosition = npc.transform.position; this.detectrange = detectrange; this.typeToDetect = typeToDetect; this.gunTipPosition = gunTipPosition; npcDetector = new NPCDetector(); randomAngle = Random.rotation; stateID = StateID.EnemyWanderStateID; }
public static List <Goal> GoalsFor(NpcType npcType) { if (npcType == NpcType.FARMER) { return(farmerGoals); } else if (npcType == NpcType.MERCENARY) { return(mercenaryGoals); } else { return(new List <Goal>()); } }
public GameObject CreateNpc(ref NpcType npcType) { //任务模型随机, 从10种模型中随机选择一种 int randomNpcModel = UnityEngine.Random.Range(0, 10); npcType = NpcTypeList[randomNpcModel]; string modleName = StringMgr.NpcModelNameList[randomNpcModel]; GameObject npcGo = ObjectManager.Instance.Instantiate(modleName); if (npcGo == null) { return(null); } return(npcGo); }
/// <summary> /// Removes npc from cell. /// </summary> public void RemoveNPC(NpcType type, ushort typeId, byte count) { var npcs = NPCs.Values.Where(n => n.Type == type && n.TypeId == typeId).Take(count); foreach (var npc in npcs) { if (NPCs.TryRemove(npc.Id, out var removedNpc)) { RemoveListeners(removedNpc); foreach (var player in GetAllPlayers(true)) { Map.PacketFactory.SendNpcLeave(player.GameSession.Client, npc); } } } }
private Vector3 GetPosFromType(NpcHtnContext ctx, NpcType fleeType) { Vector3 posToFleeTo; switch (fleeType) { case NpcType.Police: posToFleeTo = ctx.Position - (ctx.ClosestPolice.transform.position - ctx.Position).normalized * 20; break; default: throw new ArgumentOutOfRangeException(nameof(fleeType), fleeType, null); } return(posToFleeTo); }
// Use this for initialization public void InitHud(float offsetY, string nick, NpcType type) { var currColor = type == NpcType.Hero ? HeroColor : EnemyColor; nameText = gameObject.GetChild <Text>("NameText"); if (nameText != null) { nameText.text = nick; nameText.color = currColor; } heathBar = gameObject.GetChild <Image>("HealthBar/Fill Area"); if (type == NpcType.Enemy) { heathBar.color = currColor; } }
public bool moveToNpc2(NpcType type) { if (TeamSystem.IsInTeam() && !TeamSystem.IsTeamLeader() && !TeamSystem.AwayTeam(GamePlayer.Instance.InstId)) { return(true); } Avatar player = Prebattle.Instance.GetSelf(); if (player != null) { player.PlayerStoped_ = false; } Prebattle.Instance.ChangeWalkEff(Prebattle.WalkState.WS_AFP); base.moveToNpc2(type); return(true); }
public GameObject getNpcInRange(NpcType npcType, Vector3 position, float range) { List <GameObject> npcList; if (NpcDictionary.TryGetValue(npcType, out npcList)) { foreach (GameObject npc in npcList) { if (Vector3.Distance(npc.transform.position, position) < range) { return(npc); } } } return(null); }
public List<NpcAccessPoint> GetDestinationsForNpcType(NpcType type, NpcAccessPoint excluded) { List<NpcAccessPoint> compatibleAPs = new List<NpcAccessPoint>(); foreach(var ap in _accessPoints) { if (ap != null) { // Make sure we are not using destinations from the same ship/planet that the NPC was spawned if (ap.transform.parent != null && excluded != null && excluded.transform.parent != null) { if (ap.transform.parent == excluded.transform.parent) { continue; } } if (ap != excluded && type.IsAccessPointCompatible(ap.type)) { compatibleAPs.Add(ap); } } } return compatibleAPs; }
public void SpawnNpc(GameObject randomPrefab, List<NpcAccessPoint> compatibleDestinations) { if (randomPrefab == null) { throw new System.ArgumentNullException("randomPrefab"); } if (compatibleDestinations == null || compatibleDestinations.Count <= 0) { throw new System.ArgumentNullException("compatibleDestinations"); } Debug.Log(string.Format("Spawned an NPC at: {0}", Time.time)); GameObject npc = Instantiate(randomPrefab, transform.position, transform.rotation) as GameObject; _spawningNpc = npc.GetComponent<NpcType>(); if (_spawningNpc != null) { _spawningNpc.Spawn(this); } else { Debug.LogError("An NPC is missing its NpcType component"); } AINavigator npcNav = npc.GetComponent<AINavigator>(); if (npcNav != null) { GameObject destination = compatibleDestinations[Random.Range(0, compatibleDestinations.Count - 1)].gameObject; npcNav.Start(destination); } else { Debug.LogError("An NPC is missing its AINavigator component"); } }