SpawnObjectType GetObjectType(bool is_right) { float sum = 0.0f; for (int i = 0; i < (int)SpawnObjectType.Last; i++) { sum += m_SpawnObjects[(SpawnObjectType)i].m_Chance; } float rand = Random.Range(0, sum); SpawnObjectType res_obj_type = SpawnObjectType.Last; sum = 0.0f; for (int i = 0; i < (int)SpawnObjectType.Last; i++) { float chance = m_SpawnObjects[(SpawnObjectType)i].m_Chance; if (sum < rand && rand <= (sum + chance)) { res_obj_type = (SpawnObjectType)i; break; } sum += chance; } if (res_obj_type == SpawnObjectType.Last) { Debug.LogWarning("error"); } return(res_obj_type); }
public void SetType(SpawnObjectType type) { m_Type = type; if (m_Type == SpawnObjectType.Vase) { InitVase(); } }
public SpawnData(SpawnObjectType t) { type = t; spawnPoint = new WorldLocation(); terrainSwapMap = -1; spawnDifficulties = new List <Difficulty>(); dbData = true; }
public bool Spawn(float spawn_move, bool is_right) { float privilege = Mathf.Abs(m_LeftOrRightPrivilege); privilege *= is_right == (m_LeftOrRightPrivilege > 0.0) ? 1.0f : -1.0f; const float max_privilege = 10.0f; privilege *= max_privilege; // Debug.Log(m_LeftOrRightPrivilege + " " + privilege + " " + m_DeltaSpawnMove); // Should we do this? float min_delta_spawn_move = 4.0f; float max_delta_spawn_move = 15.0f; float res_delta_spawn_move = m_DeltaSpawnMove - privilege; res_delta_spawn_move = Mathf.Clamp(res_delta_spawn_move, min_delta_spawn_move, max_delta_spawn_move); if (spawn_move > res_delta_spawn_move * m_SpeedDeltaSpawnMoveCoef) { Vector3 pos = new Vector3(3.0f * (is_right ? 1.0f : -1.0f), 30.0f, 0.0f); GameObject go = MonoBehaviour.Instantiate(m_GameContr.m_FallingObject, pos, Quaternion.identity) as GameObject; FallingObject falling_obj = (FallingObject)go.GetComponent(typeof(FallingObject)); m_GameContr.GetConveyor(is_right).AddObject(falling_obj); falling_obj.SetRotationSpeed((Random.value - 0.5f) * 10.0f); falling_obj.transform.rotation = Quaternion.Euler(0.0f, 0.0f, Random.value * 360.0f); // select object SpawnObjectType obj_type = GetObjectType(is_right); falling_obj.SetType(obj_type); SpawnObjectsInfo obj_info = m_SpawnObjects[obj_type]; go.rigidbody2D.mass = obj_info.m_Mass; SpriteRenderer sprite_rend = falling_obj.GetComponentInChildren(typeof(SpriteRenderer)) as SpriteRenderer; Sprite sprite = Resources.Load <Sprite>(obj_info.m_SpriteName); if (!sprite) { Debug.LogWarning("Can't load Cake"); } sprite_rend.sprite = sprite; float scale = 1.0f; go.transform.localScale = new Vector3(scale, scale, 1.0f); return(true); } else { return(false); } }
public void GetByID_OneItem_ReturnsSpawnObjectType() { // Arrange SpawnObjectType entity = new SpawnObjectType { ID = 1 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObjectType>(entity)); // Assert Assert.AreNotSame(entity, _cache.GetByID(1)); }
/// <summary> /// スポーンオブジェクトの種類からプレハブを取得する /// </summary> /// <param name="type"></param> /// <returns></returns> private GameObject GetPrefabFromType(SpawnObjectType type) { foreach (var p in prefabs) { if (p.type == type) { return(p.prefab); } } Assert.IsTrue(false, "存在しないtypeが選択されました"); return(null); }
// Selects proper template overload to call based on passed type public uint IsPartOfAPool(SpawnObjectType type, ulong spawnId) { switch (type) { case SpawnObjectType.Creature: return(IsPartOfAPool <Creature>(spawnId)); case SpawnObjectType.GameObject: return(IsPartOfAPool <GameObject>(spawnId)); default: Cypher.Assert(false, $"Invalid spawn type {type} passed to PoolMgr.IsPartOfPool (with spawnId {spawnId})"); return(0); } }
public void GetByID_TwoItems_ReturnsCorrectObject() { // Arrange SpawnObjectType entity1 = new SpawnObjectType { ID = 1 }; SpawnObjectType entity2 = new SpawnObjectType { ID = 2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObjectType>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObjectType>(entity2)); // Assert Assert.AreNotSame(entity1, _cache.GetByID(1)); Assert.AreNotSame(entity2, _cache.GetByID(2)); }
public void GetByID_RemovedItem_ReturnsCorrectObject() { // Arrange SpawnObjectType entity1 = new SpawnObjectType { ID = 1 }; SpawnObjectType entity2 = new SpawnObjectType { ID = 2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObjectType>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObjectType>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <SpawnObjectType>(entity1)); // Assert Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(1); }); Assert.AreNotSame(entity2, _cache.GetByID(2)); }
public void GetByID_NoItems_ThrowsKeyNotFoundException() { // Arrange SpawnObjectType entity1 = new SpawnObjectType { ID = 1 }; SpawnObjectType entity2 = new SpawnObjectType { ID = 2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObjectType>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <SpawnObjectType>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <SpawnObjectType>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <SpawnObjectType>(entity2)); // Assert Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(1); }); Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(2); }); }
public SpawnObjectsInfo(SpawnObjectType type) { m_Type = type; switch (m_Type) { case SpawnObjectType.Samovar: m_Chance = 1.0f; m_Mass = 3.0f; // m_Mass = 30.0f; m_SpriteName = "coin1"; break; case SpawnObjectType.Cupboard: m_Chance = 0.3f; m_Mass = 5.0f; m_SpriteName = "coin2"; break; case SpawnObjectType.Piano: m_Chance = 0.1f; m_Mass = 10.0f; m_SpriteName = "coin3"; break; case SpawnObjectType.Vase: m_Chance = 0.06f * LevelsSettings.GetVaseFallingAccelerationCoef(); // m_Chance = 2.0f; m_Mass = 6.0f; m_SpriteName = "vase1"; break; default: Debug.LogWarning("wrong type"); break; } }
/// <summary> /// スポーン判定に成功したらスポーンさせる処理 /// </summary> /// <param name="type"></param> public GameObject SpawnIfSucceed(SpawnObjectType type, Vector3 basePoint, int laneNum) { GameObject prefab = GetPrefabFromType(type); PlacementType placementType = prefab.GetComponent <StageObject>().GetPlacementType(); //幅が広いオブジェクトの場合、レーンが1番(真ん中)出ないと生成できない if (placementType == PlacementType.Wide && laneNum != 1) { return(null); } Vector3 offset = new Vector3(0, GetYOffset(placementType), 0); Vector3 spawnPosition = basePoint + offset; //スポーンテストをする //まず、無効な値をすべて削除する spawnedObjects.RemoveAll(obj => obj == null); bool succeeded = true; //同じ座標に生成するのは無効にする foreach (var obj in spawnedObjects) { PlacementType obj_pracementType = obj.GetComponent <StageObject>().GetPlacementType(); if (Vector3.Distance(obj.transform.position, spawnPosition) < Mathf.Epsilon) { succeeded = false; } //幅の広いオブジェクトの場合、距離で判定する if (obj_pracementType == PlacementType.Wide) { Vector3 a = new Vector3(spawnPosition.x, 0.0f, spawnPosition.z); Vector3 b = new Vector3(obj.transform.position.x, 0.0f, obj.transform.position.z); if (Vector3.Distance(a, b) < stageParameter.wideObjectJudgeRadius) { succeeded = false; } } //高さのあるオブジェクトの場合、xz座標で判定する if (obj_pracementType == PlacementType.High) { Vector3 a = new Vector3(spawnPosition.x, 0.0f, spawnPosition.z); Vector3 b = new Vector3(obj.transform.position.x, 0.0f, obj.transform.position.z); if (Vector3.Distance(a, b) < Mathf.Epsilon) { succeeded = false; } } } //幅の広いオブジェクトを配置するときは、左右のレーンも調べる if (placementType == PlacementType.Wide) { foreach (var obj in spawnedObjects) { Vector3 a = new Vector3(spawnPosition.x, 0.0f, spawnPosition.z); Vector3 b = new Vector3(obj.transform.position.x, 0.0f, obj.transform.position.z); if (Vector3.Distance(a, b) < stageParameter.wideObjectJudgeRadius) { succeeded = false; } //幅の広いオブジェクト同士はもっと距離を開ける if (obj.GetComponent <StageObject>().GetPlacementType() == PlacementType.Wide && Vector3.Distance(a, b) < stageParameter.wideObjectJudgeRadius * 3.0f) { succeeded = false; } } } //高さのあるオブジェクトを配置するときは、xz座標で判定する if (placementType == PlacementType.High) { foreach (var obj in spawnedObjects) { Vector3 a = new Vector3(spawnPosition.x, 0.0f, spawnPosition.z); Vector3 b = new Vector3(obj.transform.position.x, 0.0f, obj.transform.position.z); if (Vector3.Distance(a, b) < Mathf.Epsilon) { succeeded = false; } //高さのあるオブジェクト同士は隣接しないようにする if (obj.GetComponent <StageObject>().GetPlacementType() == PlacementType.High && Vector3.Distance(a, b) < stageParameter.highObjectJudgeDistance) { succeeded = false; } } } if (!succeeded) { return(null); } GameObject res = Instantiate(prefab, spawnPosition, Quaternion.identity); spawnedObjects.Add(res); return(res); }
static bool HandleListRespawnsCommand(CommandHandler handler, StringArguments args) { Player player = handler.GetSession().GetPlayer(); Map map = player.GetMap(); uint range = 0; if (!args.Empty()) { range = args.NextUInt32(); } Locale locale = handler.GetSession().GetSessionDbcLocale(); string stringOverdue = Global.ObjectMgr.GetCypherString(CypherStrings.ListRespawnsOverdue, locale); uint zoneId = player.GetZoneId(); string zoneName = GetZoneName(zoneId, locale); for (SpawnObjectType type = 0; type < SpawnObjectType.NumSpawnTypes; type++) { if (range != 0) { handler.SendSysMessage(CypherStrings.ListRespawnsRange, type, range); } else { handler.SendSysMessage(CypherStrings.ListRespawnsZone, type, zoneName, zoneId); } handler.SendSysMessage(CypherStrings.ListRespawnsListheader); List <RespawnInfo> respawns = new(); map.GetRespawnInfo(respawns, (SpawnObjectTypeMask)(1 << (int)type)); foreach (RespawnInfo ri in respawns) { SpawnMetadata data = Global.ObjectMgr.GetSpawnMetadata(ri.type, ri.spawnId); if (data == null) { continue; } uint respawnZoneId = 0; SpawnData edata = data.ToSpawnData(); if (edata != null) { respawnZoneId = map.GetZoneId(PhasingHandler.EmptyPhaseShift, edata.SpawnPoint); if (range != 0) { if (!player.IsInDist(edata.SpawnPoint, range)) { continue; } } else { if (zoneId != respawnZoneId) { continue; } } } uint gridY = ri.gridId / MapConst.MaxGrids; uint gridX = ri.gridId % MapConst.MaxGrids; string respawnTime = ri.respawnTime > GameTime.GetGameTime() ? Time.secsToTimeString((ulong)(ri.respawnTime - GameTime.GetGameTime()), TimeFormat.ShortText) : stringOverdue; handler.SendSysMessage($"{ri.spawnId} | {ri.entry} | [{gridX:2},{gridY:2}] | {GetZoneName(respawnZoneId, locale)} ({respawnZoneId}) | {respawnTime}{(map.IsSpawnGroupActive(data.spawnGroupData.groupId) ? "" : " (inactive)")}"); } } return(true); }
public SpawnMetadata(SpawnObjectType t) { type = t; }
public static bool TypeIsValid(SpawnObjectType type) { return(type < SpawnObjectType.NumSpawnTypes); }
public static bool TypeHasData(SpawnObjectType type) { return(type < SpawnObjectType.NumSpawnTypesWithData); }
public static bool TypeInMask(SpawnObjectType type, SpawnObjectTypeMask mask) { return(((1 << (int)type) & (int)mask) != 0); }
public SpawnData(SpawnObjectType t) : base(t) { SpawnPoint = new Position(); terrainSwapMap = -1; spawnDifficulties = new List <Difficulty>(); }
public SpawnData(SpawnObjectType t) { type = t; }