public static void AddEggs(Snapshot snapshot, Coordinates position, float edgeLength) { float totalEggs = SimulationSettings.HQStartingEggTRexCount + SimulationSettings.HQStartingEggBrachioCount; for (int i = 0; i < totalEggs; i++) { Vector3 offset = new Vector3(Random.Range(-edgeLength / 2, edgeLength / 2), 0, Random.Range(-edgeLength / 2, edgeLength / 2)); Coordinates coordinates = (position.ToVector3() + offset).ToCoordinates(); EntityTemplate entity = null; if (i < SimulationSettings.HQStartingEggBrachioCount) { entity = EntityTemplateFactory.CreateEggTemplate(coordinates, 0, EggTypeEnum.Brachiosaurus); } else { entity = EntityTemplateFactory.CreateEggTemplate(coordinates, 0, EggTypeEnum.TRex); } if (entity != null) { snapshot.AddEntity(entity); } } Debug.Log("Snapshot Dinosaur Eggs generated ! count<" + totalEggs + ">"); }
public void LayEgg() { EggTypeEnum eggType = 0; if (Species == SimulationSettings.Dino_Brachio_PrefabName) { eggType = EggTypeEnum.Brachiosaurus; } else if (Species == SimulationSettings.Dino_TRex_PrefabName) { eggType = EggTypeEnum.TRex; } // 恐龙自己下蛋 var exampleEntity = EntityTemplateFactory.CreateEggTemplate(transform.position.ToCoordinates(), attrsWriter.Data.OwnerTokenId, eggType); var request1 = new WorldCommands.CreateEntity.Request(exampleEntity); worldCommandSender.SendCreateEntityCommand(request1, OnCreateEggResponse); //Debug.Log("DinoBehaviour LayEgg! Egg type : "+eggType); }
void OnLayEgg(PlayerAttrs.LayEgg.ReceivedRequest request) { Coordinates coords = request.Payload.EggPosition.ToUnityVector().ToCoordinates(); EggTypeEnum eggType = request.Payload.EggType; long tokenId = request.Payload.OwnerTokenId; // 得到下蛋的能量消耗 int costEnergy = 0; switch (eggType) { case EggTypeEnum.Brachiosaurus: costEnergy = CostEnergyEggBrachio; break; case EggTypeEnum.TRex: costEnergy = CostEnergyEggTRex; break; } if (attrs.Data.Energy < costEnergy) {// 能量不夠不能下蛋 string errMsg = "Energy is not enough. (" + attrs.Data.Energy + "/" + costEnergy + ")"; commandReceiver.SendLayEggFailure(request.RequestId, errMsg); return; } // 更新能量消耗 var update = new PlayerAttrs.Update { Energy = attrs.Data.Energy - costEnergy, }; attrs.SendUpdate(update); // 玩家操作下蛋:发送创建实体消息 var exampleEntity = EntityTemplateFactory.CreateEggTemplate(coords, tokenId, eggType); var request1 = new WorldCommands.CreateEntity.Request(exampleEntity); request1.Context = request.RequestId; worldCommandSender.SendCreateEntityCommand(request1, OnCreateEggResponse); }