public void MoveToPosition(Vector3 position) { foreach (AiObject aiObject in activeAiObjects) { if (aiObject == null || aiObject.behave == null || aiObject.behave.running) { continue; } if (GameConfig.IsMultiMode && !aiObject.IsController) { continue; } Vector3 patrolPosition = position + header.transform.TransformDirection(aiObject.offset - header.offset); if (AiUtil.SqrMagnitudeH(patrolPosition - aiObject.position) > 1f * 1f) { aiObject.desiredMoveDestination = patrolPosition; } else { aiObject.desiredMoveDestination = Vector3.zero; } aiObject.speed = aiObject.walkSpeed; } if (GameConfig.IsMultiMode && IsController) { RPCServer(EPacketType.PT_AG_MoveToPosition, position); } }
IEnumerator Spawn(PlayerSleepData data) { while (true) { if (IsPlayerSleeping(data)) { Vector3 position = Vector3.zero; //GetSpawnPosition( //PlayerFactory.mMainPlayer.transform.position, //data.minRadius, //data.maxRadius); Quaternion rot = Quaternion.identity; //Quaternion.LookRotation(PlayerFactory.mMainPlayer.transform.position - position, Vector3.up); int pathID = 0; int typeID = (int)AiUtil.GetPointType(position); if (Application.loadedLevelName.Equals(GameConfig.MainSceneName)) { pathID = AISpawnDataStory.GetRandomPathIDFromType(typeID, position); } else if (Application.loadedLevelName.Equals(GameConfig.AdventureSceneName)) { int mapID = AiUtil.GetMapID(position); int areaID = AiUtil.GetAreaID(position); pathID = AISpawnDataAdvSingle.GetPathID(mapID, areaID, typeID); } AIResource.Instantiate(pathID, position, rot, OnSleepSpawned); } yield return(new WaitForSeconds(data.interval)); } }
bool GetPositionAndRotation(out Vector3 pos, out Quaternion rot, float minAngle, float maxAngle) { pos = Vector3.zero; rot = Quaternion.identity; pos = AiUtil.GetRandomPosition(transform.position, mMinRadius, mMaxRadius, Vector3.forward, minAngle, maxAngle, 10.0f, AiUtil.groundedLayer, 5); if (pos != Vector3.zero) { return(true); } if (!GameConfig.IsMultiMode) { pos = AiUtil.GetRandomPosition(transform.position, mMinRadius, mMaxRadius, Vector3.forward, minAngle, maxAngle); if (pos != Vector3.zero) { return(true); } } return(false); }
public static Vector3 GetShootPosition(ISkillTarget target) { SkillRunner runner = target as SkillRunner; if (runner != null && runner.GetComponent <Collider>() != null) { AiObject aiObj = runner as AiObject; if (aiObj != null) { if (aiObj.model != null) { Rigidbody[] rigids = aiObj.model.GetComponentsInChildren <Rigidbody>(); if (rigids != null && rigids.Length > 0) { return(rigids[Random.Range(0, rigids.Length)].worldCenterOfMass); } } return(aiObj.center); } else { return(AiUtil.GetColliderCenter(runner.GetComponent <Collider>())); } } else { //CreationSkillRunner creation = runner as CreationSkillRunner; //if (creation != null) // return creation.transform.TransformPoint(creation.LocalBounds.center); //else // return target.GetPosition(); } return(Vector3.zero); }
bool Match(AiObject aiObj) { //if (aiObj == null || !aiObj.isActive || aiObj.enemy != null || aiObj.dead) // return false; return(AiUtil.GetChild(aiObj.transform, "faece") != null); }
public static Vector3 GetTargetCenter(ISkillTarget target) { SkillRunner runner = target as SkillRunner; if (runner != null && runner.GetComponent <Collider>() != null) { AiObject aiObj = runner as AiObject; if (aiObj != null) { return(aiObj.center); } else { return(AiUtil.GetColliderCenter(runner.GetComponent <Collider>())); } } else { //CreationSkillRunner creation = runner as CreationSkillRunner; //if (creation != null) //return creation.transform.TransformPoint(creation.LocalBounds.center); // else // return target.GetPosition(); } return(Vector3.zero); }
void OnTerrainMeshCreated(IntVector4 node) { if (node.w == 0) { IntVector2 mark = AiUtil.ConvertToIntVector2FormLodLevel(node, VoxelTerrainMaxLod); if (pointTable.ContainsKey(mark)) { SPTerrainRect tRect = pointTable[mark]; if (tRect != null) { List <SPPoint> points = tRect.points; points = points.FindAll(ret => Match(ret, node.x, node.z)); foreach (SPPoint point in points) { point.AttachEvent(node); //point.position = new Vector3(point.position.x, node.y, point.position.z); } } } RegisterMeshNode(node); LODOctreeMan.self.AttachNodeEvents(null, null, null, null, OnTerrainColliderCreated, node.ToVector3(), 0); } }
bool RevisePosition() { if (!mRevisePosition) { return(true); } Vector3 position = transform.position; RaycastHit hitInfo; if (AiUtil.CheckPositionOnGround(position, out hitInfo, 256.0f, 256.0f, AiUtil.groundedLayer)) { transform.position = hitInfo.point; if (!mErode || AIErodeMap.IsInErodeArea(transform.position) == null) { return(true); } } return(false); }
Vector3 GetCorrectPosition() { if (!ignoreTerrain) { for (int i = 0; i < 5; i++) { Vector3 position = AiUtil.GetRandomPosition( transform.position, 0.0f, radius, 200.0f, AiUtil.groundedLayer, 5); if (IsValid(position)) { return(position); } } } else { for (int i = 0; i < 5; i++) { Vector3 position = transform.position + Random.insideUnitSphere * radius; if (IsValid(position)) { return(position); } } } return(Vector3.zero); }
void OnEntitySpawned(SceneEntityPosAgent agent) { m_MaxCount++; if (!EntityMonsterBeacon.IsBcnMonsterProtoId(agent.protoId)) // not encoded, unexpected agent { return; } int spType, lvl, spawnType; EntityMonsterBeacon.DecodeBcnMonsterProtoId(agent.protoId, out spType, out lvl, out spawnType); int areaType = PeGameMgr.IsStory ? PeMappingMgr.Instance.GetAiSpawnMapId(new Vector2(agent.Pos.x, agent.Pos.z)) : AiUtil.GetMapID(agent.Pos); AISpawnTDWavesData.TDMonsterSpData data = AISpawnTDWavesData.GetMonsterSpData(false, spType, lvl, spawnType, areaType); float rhp = data != null ? data._rhp : 200.0f; float dps = data != null ? data._dps : 50.0f; SiegeAgent siegeAgent = new SiegeAgent(this, agent, rhp, dps); agent.spInfo = new SiegeAgent.AgentInfo(m_Beacon, siegeAgent); m_Agents.Add(siegeAgent); }
//Ai_hatch hatch; public override IEnumerator SpawnGroup() { if (res == null) { yield break; } yield return(new WaitForSeconds(delayTime)); //if (hatch != null && hatch.dead) // yield break; //hatch.ApplyDamage(hatch.maxLife + 100.0f); int count = Random.Range(minCount, maxCount); for (int i = 0; i < count; i++) { Vector3 position = transform.position + Random.insideUnitSphere * radius; if (AiUtil.CheckPositionOnGround(ref position, 10.0f, AiUtil.groundedLayer)) { AIResource.Instantiate(id, position, Quaternion.identity, OnSpawned); yield return(new WaitForSeconds(0.1f)); } } yield return(new WaitForSeconds(0.5f)); yield break; }
public void InstantiateEffect(int effId, Transform caster, Transform target = null, EffectInstantiateCompleted OnInstantiated = null) { EffCastData data = EffCastData.GetEffCastData(effId); if (data == null) { return; } Transform tr = null; if (string.IsNullOrEmpty(data.m_posStr) || data.m_posStr.Equals("0")) { tr = caster; } else { tr = AiUtil.GetChild(caster, data.m_posStr); } if (tr == null) { return; } Transform parent = data.m_bind ? tr : null; Instantiate(effId, tr, parent, target, OnInstantiated); }
public void RunawayForPosition(Vector3 position) { if (!GameConfig.IsMultiMode) { foreach (AiObject aiObject in activeAiObjects) { if (aiObject != null && !aiObject.dead) { if (GameConfig.IsMultiMode && !aiObject.IsController) { continue; } Vector3 direction = (aiObject.position - position).normalized; direction = AiUtil.RunawayDirectionCorrect(aiObject, direction); aiObject.speed = aiObject.runSpeed; aiObject.desiredMoveDestination = aiObject.position + direction.normalized * 2; } } } if (GameConfig.IsMultiMode && IsController) { RPCServer(EPacketType.PT_AG_RunawayForPosition, position); } }
bool CheckMovementValidLand(Vector3 movement) { //DodgeNeighbours(ref movement); float deltaTime = (this is AiPhysicsCharacterMotor) ? Time.fixedDeltaTime : Time.deltaTime; Vector3 newMovement = movement; newMovement.y = 0.0f; Vector3 deltaMovement = newMovement.normalized * maxForwardSpeed * deltaTime * 10.0f; //Vector3 nextFeetPos = transform.position + transform.forward * radius + deltaMovement; //if (!AiUtil.CheckPositionOnGround(nextFeetPos, 5.0f, AiManager.Manager.groundedLayer)) // return false; Vector3 nextPos = aiObject != null ? aiObject.center : transform.position; nextPos += transform.forward * radius; nextPos += deltaMovement; if (AiUtil.CheckPositionUnderWater(nextPos)) { return(false); } return(true); }
public JokerPoint betterPlanMove(JokerGame game) { if (orderMap == null) { initOrderMap(game.getHeight()); } int n = game.getHeight(); JokerMove prevMove; if ((prevMove = game.getLastMove()) != null) { int row = prevMove.getLocation().x; int col = prevMove.getLocation().y; updateOrderMap(row, col, n); } char[,] tmpBoard = game.getBoardCopy(); int best = int.MinValue; List <JokerPoint> bestMoves = new List <JokerPoint>(); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (tmpBoard[i, j] != '*') { continue; } tmpBoard[i, j] = color; int heuristic = AiUtil.getLiberties(getColor(), tmpBoard); heuristic -= (AiUtil.getLiberties(getOpponentColor(), tmpBoard) * 2); heuristic += orderMap[i, j]; if (heuristic > best) { best = heuristic; bestMoves.Clear(); bestMoves.Add(new JokerPoint(i, j)); } else if (heuristic == best) { bestMoves.Add(new JokerPoint(i, j)); } tmpBoard[i, j] = '*'; } } JokerPoint bestMove = bestMoves[Randomizer.Next(bestMoves.Count)]; updateOrderMap(bestMove.x, bestMove.y, n); return(bestMove); }
public void RemoveMeshNode(IntVector4 node) { IntVector2 mark = AiUtil.ConvertToIntVector2FormLodLevel( node, LODOctreeMan._maxLod); if (mMeshNodes.Contains(mark)) { mMeshNodes.Remove(mark); } }
static int GetBossMonsterProtoID(Vector3 pos, float rndVal, ref float fScale) { int pathID = 0, typeID = 0; typeID = (int)AiUtil.GetPointType(pos); int mapID = AiUtil.GetMapID(pos); int areaID = AiUtil.GetAreaID(pos); pathID = AISpawnDataAdvSingle.GetBossPathIDScale(mapID, areaID, typeID, rndVal, ref fScale); return(pathID); }
protected override int GetCurrentBgMusicID() { Vector3 camPos = PETools.PEUtil.MainCamTransform.position; if (AiUtil.CheckPositionInCave(camPos, 128.0f, AiUtil.groundedLayer)) { return(836); } int x = (int)camPos.x; int z = (int)camPos.z; if (x <= Int32.MinValue) { Debug.LogError("x value too small!"); x = Int32.MinValue + 1; } if (z <= Int32.MinValue) { Debug.LogError("z value too small!"); z = Int32.MinValue + 1; } if (VFDataRTGen.IsSea(x, z)) { return(AISpawnDataStory.GetBackGroundMusic(new Color(255.0f / 255.0f, 100.0f / 255.0f, 150.0f / 255.0f, 255 / 255.0f))); } else { RandomMapType mapType = VFDataRTGen.GetXZMapType(x, z); switch (mapType) { case RandomMapType.GrassLand: return(AISpawnDataStory.GetBackGroundMusic(new Color(30.0f / 255.0f, 50.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f))); case RandomMapType.Forest: return(AISpawnDataStory.GetBackGroundMusic(new Color(70.0f / 255.0f, 70.0f / 255.0f, 70.0f / 255.0f, 255 / 255.0f))); case RandomMapType.Desert: return(AISpawnDataStory.GetBackGroundMusic(new Color(140.0f / 255.0f, 100.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f))); case RandomMapType.Redstone: return(AISpawnDataStory.GetBackGroundMusic(new Color(170.0f / 255.0f, 70.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f))); case RandomMapType.Rainforest: return(AISpawnDataStory.GetBackGroundMusic(new Color(90.0f / 255.0f, 90.0f / 255.0f, 90.0f / 255.0f, 255 / 255.0f))); case RandomMapType.Mountain: return(AISpawnDataStory.GetBackGroundMusic(new Color(170.0f / 255.0f, 70.0f / 255.0f, 150.0f / 255.0f, 255 / 255.0f))); case RandomMapType.Swamp: return(AISpawnDataStory.GetBackGroundMusic(new Color(100.0f / 255.0f, 50.0f / 255.0f, 50.0f / 255.0f, 255 / 255.0f))); case RandomMapType.Crater: return(AISpawnDataStory.GetBackGroundMusic(new Color(180.0f / 255.0f, 180.0f / 255.0f, 180.0f / 255.0f, 255 / 255.0f))); default: return(0); } } }
// bool CanSpawn() // { // if (GameConfig.IsMultiMode) // return overlay || AiNetworkManager.Instance.GetGroupAiNetwork(OwnerView.viewID.id).Count <= 0; // else // return overlay || aiObjects.Count <= 0; // } bool CheckOnTerrain() { Vector3 pos = transform.position; if (AiUtil.CheckPositionOnGround(ref pos, 10.0f, AiUtil.groundedLayer)) { transform.position = pos; return(true); } return(false); }
bool CheckBones() { if (null == LeftFootBone) { LeftFootBone = AiUtil.GetChild(transform, "Bip01 L Foot"); } if (null == RightFootBone) { RightFootBone = AiUtil.GetChild(transform, "Bip01 R Foot"); } return(null != LeftFootBone && null != RightFootBone); }
protected override int GetCurrentBgMusicID() { Vector3 camPos = PETools.PEUtil.MainCamTransform.position; if (AiUtil.CheckPositionInCave(camPos, 128.0f, AiUtil.groundedLayer)) { return(836); } Vector2 pos = new Vector2(camPos.x, camPos.z); return(AISpawnDataStory.GetBgMusicID(PeMappingMgr.Instance.GetAiSpawnMapId(pos))); }
bool IsValid(Vector3 position) { AiObject[] aiObjects = transform.GetComponentsInChildren <AiObject>(); foreach (AiObject ite in aiObjects) { if (AiUtil.SqrMagnitudeH(ite.position - position) < rejectRadius * rejectRadius) { return(false); } } return(true); }
bool IsRevisePosition() { float distance = VoxelTerrainConstants._numVoxelsPerAxis; RaycastHit hitInfo; if (AiUtil.CheckPositionOnGround(position, out hitInfo, distance, distance, AiUtil.groundedLayer)) { position = hitInfo.point; return(true); } return(false); }
Vector3 GetPosition(IntVector4 node) { for (int i = 0; i < 10; i++) { Vector3 pos = AiUtil.GetRandomPosition(node); if (!IsInCSCommon(pos)) { return(pos); } } return(Vector3.zero); }
Vector3 GetRandomPosition(AISpawnData data, Vector3 center) { for (int i = 0; i < 10; i++) { Vector3 pos = AiUtil.GetRandomPosition(center, minRadius, maxRadius, Vector3.forward, data.minAngle, data.maxAngle); if (!IsInCSCommon(pos)) { return(pos); } } return(Vector3.zero); }
void OnTerrainColliderCreated(IntVector4 node) { if (node.w == 0) { IntVector2 mark = new IntVector2(node.x, node.z); if (!mExists.Contains(mark)) { if (Random.value < probability) { Vector3 pos = AiUtil.GetRandomPosition(node); if (AiUtil.CheckPositionOnGround(ref pos, 0.0f, VoxelTerrainConstants._numVoxelsPerAxis << node.w, AiUtil.groundedLayer)) { if (!AiUtil.CheckPositionUnderWater(pos)) { GameObject faece = Instantiate(GetRandomFaeces(), pos, Quaternion.identity) as GameObject; faece.transform.parent = transform; mFaeces.Add(faece); StartCoroutine(DestroyFaece(faece, 400.0f)); } } } mExists.Add(mark); } List <GameObject> faeces = mFaeces.FindAll(ret => MatchFaece(node, ret)); foreach (GameObject ite in faeces) { Vector3 pos = ite.transform.position; float distance = pos.y - node.y; if (distance > PETools.PEMath.Epsilon) { RaycastHit hitInfo; if (Physics.Raycast(pos + Vector3.up * 0.1f, Vector3.down, out hitInfo, distance, AiUtil.groundedLayer)) { if (ite.GetComponent <Rigidbody>() != null) { ite.GetComponent <Rigidbody>().useGravity = true; } } } } } }
void Copy() { if (source == null || target == null) { return; } CopySerialized(source.transform, target.transform); Transform[] transforms = source.GetComponentsInChildren <Transform>(); foreach (Transform tr in transforms) { CopySerialized(tr, AiUtil.GetChild(target.transform, tr.name)); } }
void Start() { // Add player's own layer to mask mask = 1 << gameObject.layer; // Add Igbore Raycast layer to mask mask |= 1 << LayerMask.NameToLayer("Ignore Raycast"); // Invert mask mask = ~mask; armIKSrcLeft = AiUtil.GetChild(transform, "IKHandLeft"); armIKSrcRight = AiUtil.GetChild(transform, "IKHandRight"); localPosition = aimWeapon.localPosition; localRotation = aimWeapon.localRotation; distance = Vector3.Distance(aimPivot.position, aimWeapon.position); }
void RemoveSPTerrainRect(IntVector4 node) { IntVector2 mark = AiUtil.ConvertToIntVector2FormLodLevel(node, VoxelTerrainMaxLod); if (pointTable.ContainsKey(mark)) { pointTable[mark].RemoveMeshNode(node); if (pointTable[mark].meshNodes.Count <= 0) { pointTable[mark].Destroy(); pointTable.Remove(mark); //Debug.Log("Destroy SPTerrainRect at position[" + mark.x + " , " + mark.y + "]"); } } }
public SPTerrainRect GetSPTerrainRect(Vector3 position) { if (position == Vector3.zero) { return(null); } IntVector4 node = AiUtil.ConvertToIntVector4(position, 3); IntVector2 mark = new IntVector2(node.x, node.z); if (pointTable.ContainsKey(mark)) { return(pointTable[mark]); } return(null); }