/// <summary> 加载怪物镜像(不实例化) </summary> /// <param name="monsterId"></param> /// <returns></returns> public GameObject LoadMonster(int monsterId) { MonsterEntity entity = MonsterDBModel.Instance.Get(monsterId); if (entity == null) { return(null); } return(AssetBundleManager.Instance.Load(string.Format("Download/{0}/{1}.assetbundle", entity.FloaderName, entity.PrefabName), entity.PrefabName)); }
/// <inheritdoc /> public IMonsterEntity CreateMonster(IMapInstance currentMap, IMapLayer currentMapLayer, int moverId, IMapRespawnRegion region, bool respawn = false) { if (!_gameResources.Movers.TryGetValue(moverId, out MoverData moverData)) { throw new ArgumentException($"Cannot find mover with id '{moverId}' in game resources.", nameof(moverId)); } var monster = new MonsterEntity { Object = new ObjectComponent { ModelId = moverId, Name = moverData.Name, Level = moverData.Level, Type = WorldObjectType.Mover, Size = ObjectComponent.DefaultObjectSize, MovingFlags = ObjectState.OBJSTA_STAND, Position = region.GetRandomPosition(), Angle = RandomHelper.FloatRandom(0, 360f), Spawned = true, AbleRespawn = respawn, CurrentMap = currentMap, LayerId = currentMapLayer.Id }, Timers = new TimerComponent { NextMoveTime = Time.TimeInSeconds() + RandomHelper.LongRandom(8, 20) } }; monster.Moves = new MovableComponent { Speed = moverData.Speed }; monster.Data = moverData; monster.Region = region; monster.Attributes[DefineAttributes.HP] = moverData.AddHp; monster.Attributes[DefineAttributes.MP] = moverData.AddMp; monster.Attributes[DefineAttributes.STR] = moverData.Strength; monster.Attributes[DefineAttributes.STA] = moverData.Stamina; monster.Attributes[DefineAttributes.DEX] = moverData.Dexterity; monster.Attributes[DefineAttributes.INT] = moverData.Intelligence; monster.Behavior = _behaviorManager.GetBehavior(BehaviorType.Monster, monster, moverId); monster.Hand = _itemFactory.CreateItem(11, 0, ElementType.None, 0); if (moverData.Class == MoverClassType.RANK_BOSS) { monster.Object.Size *= 2; } return(monster); }
private void CreateMonster(float x, float y) { MonsterEntity monster = new MonsterEntity(MonsterType.Farmer, x, y); monster.Radius = 200; monster.FloorY = Floor.Y; monster.ImageLoaded += Monster_ImageLoaded; monster.Damage = 1; monster.Distance = 100; monster.HealthPoints = 3; MonsterEntities.Add(monster); }
public void UpdateItem(MonsterEntity entity) { this.entity = entity; if (entity != null) { IconView.UpdateView(entity.masterId); } else { IconView.gameObject.SetActive(false); } }
/// <summary> /// Create a new monster. /// </summary> /// <param name="moverData">Monster's data</param> /// <param name="respawnRegion">Respawn region</param> /// <returns></returns> private MonsterEntity CreateMonster(MoverData moverData, IMapRespawnRegion respawnRegion) { var monster = new MonsterEntity(this); var behaviors = DependencyContainer.Instance.Resolve <BehaviorLoader>(); monster.Object = new ObjectComponent { MapId = this.Parent.Id, LayerId = this.Id, ModelId = moverData.Id, Type = WorldObjectType.Mover, Position = respawnRegion.GetRandomPosition(), Angle = RandomHelper.FloatRandom(0, 360f), Name = moverData.Name, Size = ObjectComponent.DefaultObjectSize, Spawned = true, Level = moverData.Level }; monster.Timers = new TimerComponent { NextMoveTime = RandomHelper.LongRandom(8, 20) }; monster.MovableComponent = new MovableComponent { Speed = moverData.Speed, DestinationPosition = monster.Object.Position.Clone() }; monster.Health = new HealthComponent { Hp = moverData.AddHp, Mp = moverData.AddMp, Fp = 0 }; monster.Statistics = new StatisticsComponent { Strength = (ushort)moverData.Strength, Stamina = (ushort)moverData.Stamina, Dexterity = (ushort)moverData.Dexterity, Intelligence = (ushort)moverData.Intelligence }; monster.Behavior = behaviors.MonsterBehaviors.GetBehavior(monster.Object.ModelId); monster.Region = respawnRegion; monster.Data = moverData; if (moverData.Class == MoverClassType.RANK_BOSS) { monster.Object.Size *= 2; } return(monster); }
/// <summary> /// 获得角色信息 /// </summary> /// <param name="monsterID">角色ID</param> /// <returns>角色信息</returns> public MonsterEntity GetMonster(int monsterID) { MonsterEntity monster = null; foreach (MonsterEntity item in MonsterList) { if (item.id == monsterID) { monster = item; break; } } return(monster); }
public void SetMonsterData(MonsterEntity entity) { NickName = entity.Name; CurrHP = MaxHP = entity.HP; //CurrHP = MaxHP = entity.HP+99999999; Attack = entity.Attack; Defense = entity.Defense; Res = entity.ResDefense; Hit = entity.Hit; Dodge = entity.Dodge; Cri = entity.Cri; int fighting = FightingUtil.CalculateRoleFighting(MaxHP, Attack, AttackAddition, Defense, DefenseAddition, Res, ResAddition, Hit, HitAddition, Dodge, DodgeAddition, Cri, CriAddition); SetFighting(fighting); }
void SyncMonster(MonsterEntity monsterEntity) { int entityID = monsterEntity.entityID; int monsterHealth = monsterEntity.monsterHealth; Vector3 monsterPosition = new Vector3 { x = monsterEntity.location.x, y = monsterEntity.location.y, z = monsterEntity.location.z }; Quaternion monsterRotation = Quaternion.Euler( monsterEntity.rotation.x, monsterEntity.rotation.y, monsterEntity.rotation.z ); GameObject monster = FindMonsterWithID(entityID); if (monster != null) { EnemyHealth enemyHealth = monster.GetComponent <EnemyHealth>(); if (enemyHealth != null) { monsterPosition.y = monster.transform.position.y; //monster.transform.position = monsterPosition; monster.transform.rotation = monsterRotation; Vector3 movement = monsterPosition - monster.transform.position; UpdateServerGameObjectsMovement(GameSettings.MONSTER_TYPE, entityID, movement); if (monsterHealth < enemyHealth.currentHealth) { enemyHealth.enemyAudio.Play(); enemyHealth.currentHealth = monsterHealth; enemyHealth.SetHealthImage(); if (enemyHealth.currentHealth <= 0) { DeleteServerGameobjects(GameSettings.MONSTER_TYPE, entityID); } } } } }
/// <summary> /// /// </summary> /// <param name="prospection"></param> /// <param name="monster"></param> /// <param name="rate"></param> /// <returns></returns> public List <ItemDAO> GetDrops(long prospection, MonsterEntity monster, double rate) { var drops = new List <ItemDAO>(); foreach (var drop in monster.Grade.Template.Drops) { for (var i = 0; i < drop.Max; i++) { if (TryDrop(prospection, drop, rate)) { if (drop.ItemTemplate != null) { drops.Add(drop.ItemTemplate.Create()); } } } } return(drops); }
/// <summary> 刷怪 </summary> private void CreateMonster() { //临时测试 //if (m_CurrRegionCreateMonsterCount>=1) return; if (m_RegionMonsterList.Count == 0) { return; } for (int i = 0; i < 1; i++) { m_Index = UnityEngine.Random.Range(0, m_RegionMonsterCountList.Count); if (m_RegionMonsterCountList[m_Index] == 0) { i--; } } int monsterId = m_RegionMonsterList[m_Index].MonsterId; RoleInfoMonster monsterInfo = new RoleInfoMonster(); MonsterEntity monsterEntity = MonsterDBModel.Instance.Get(monsterId); monsterInfo.MonsterEntity = monsterEntity; monsterInfo.GameLevelMonsterEntity = GameLevelMonsterDBModel.Instance.GetGameLevelMonsterEntity(GameLevelCtrl.Instance.ChapterId, GameLevelCtrl.Instance.GameLevelId, m_CurrRegionIndex + 1, monsterId); monsterInfo.RoleId = ++m_MonsterTempId; m_KillMonsterIdList.Add(monsterInfo.RoleId); monsterInfo.SetMonsterData(monsterEntity); //从池子中取怪 Transform monsterTrans = m_MonsterPool.Spawn(MonsterDBModel.Instance.Get(monsterId).PrefabName); //将怪放在出生点 Transform monsterBornPos = m_CurrRegionctrl.MonsterBornPos[UnityEngine.Random.Range(0, m_CurrRegionctrl.MonsterBornPos.Length)]; RoleCtrl monsterCtrl = monsterTrans.GetComponent <RoleCtrl>(); monsterCtrl.PatrolRadius = monsterEntity.PatrolRadius; monsterCtrl.ViewRadius = monsterEntity.ViewRadius; monsterCtrl.Speed = monsterEntity.MoveSpeed; monsterCtrl.Init(RoleType.Monster, monsterInfo, new GameLevelRoleMonsterAI(monsterCtrl, monsterInfo)); monsterCtrl.OnRoleDie = OnRoleDieCallBack; monsterCtrl.OnRoleDestroy = OnRoleDestroyCallBack; monsterCtrl.SetBornPoint(monsterBornPos.TransformPoint(UnityEngine.Random.Range(-0.5f, 0.5f), 0, UnityEngine.Random.Range(-0.5f, 0.5f))); m_RegionMonsterCountList[m_Index]--; m_CurrRegionCreateMonsterCount++; }
void CreateMonster(MonsterEntity monsterEntity) { int monsterStyle = monsterEntity.monsterType; Vector3 monsterPosition = new Vector3 { x = monsterEntity.location.x, y = monsterEntity.location.y, z = monsterEntity.location.z }; Quaternion monsterRotation = Quaternion.Euler( monsterEntity.rotation.x, monsterEntity.rotation.y, monsterEntity.rotation.z ); int eneityID = monsterEntity.entityID; GameObject newEnemy = null; if (monsterStyle == 0) { newEnemy = Instantiate(Zombunny, monsterPosition, monsterRotation); } else if (monsterStyle == 1) { newEnemy = Instantiate(Zombear, monsterPosition, monsterRotation); } else if (monsterStyle == 2) { newEnemy = Instantiate(Hellephant, monsterPosition, monsterRotation); } EnemyHealth enemyHealth = newEnemy.GetComponent <EnemyHealth>(); enemyHealth.monsterID = eneityID; enemyHealth.monsterStyle = monsterStyle; enemyHealth.currentHealth = monsterEntity.monsterHealth; AddServerGameObjects(GameSettings.MONSTER_TYPE, eneityID, newEnemy); }
public void UpdateView(MonsterEntity entity) { if (entity == null || entity == currentEntity) { return; } currentEntity = entity; ResourceUtilities.Instance.LoadMonsterIcon(entity.masterId, (sprite) => { icon.sprite = sprite; PlayIconAppearAnimation(); }); nickName.text = entity.nickname; hp.text = entity.hp.ToString(); attack.text = entity.attack.ToString(); defence.text = entity.defence.ToString(); dodge.text = entity.dodge.ToString(); critical.text = entity.critical.ToString(); }
//Enable undo/redo by saving the game state at the time of command execution public ArrowKeyActionCommand(MainViewModel MVM, CharacterEntity.Direction direction) { this.MVM = MVM; this.direction = direction; this.monsterFocus = MVM.monsterFocus; this.items_state = new ObservableCollection <ItemEntity>(); this.monsters_state = new ObservableCollection <MonsterEntity>(); this.random_state = Entity.rnd.NumberOfInvokes; player_state = new PlayerEntity(MVM.player); damagedMonster = -1; foreach (MonsterEntity otherMonster in MVM.monsters) { monsters_state.Add(new MonsterEntity(otherMonster)); } foreach (ItemEntity otherItem in MVM.items) { items_state.Add(new ItemEntity(otherItem)); } }
public Initialise(int load, Action LoadNextLevel) { //Things that need to be done before old level data is wiped SaveData sav = new SaveData(); //Save player hp between levels int playerhp = 20; int[] playerarmor = { 0, 0, 0 }; int[] playerdp = { 1, 2 }; if (load > 1) { playerhp = collection.player.hp; playerarmor[0] = collection.player.armor; playerarmor[1] = collection.player.boots; playerarmor[2] = collection.player.gauntlets; playerdp[0] = collection.player.minDp; playerdp[1] = collection.player.maxDp; } //Wiping old level data collection = new Collections(); //Initialise monsters collection.monsters = new ObservableCollection <MonsterEntity>(); //Initialise items collection.items = new ObservableCollection <ItemEntity>(); //Initialise triggers collection.triggers = new ObservableCollection <TriggerEntity>(); // loads data in case we are loading a saved game if (load < 0) { LoadGame Load = new LoadGame(-load); sav = Load.LoadSave(); collection.level = sav.Level; } else//if we aren't we use the input int to load the level { collection.level = load; } //Initialise map MapData mp = new MapData(); MapLoad MapInfo = new MapLoad(collection.level); mp = MapInfo.GetMap(); collection.map = new Map(mp.Mapst); //taking into account save game modifying data int monstatsLength = mp.Monstats.GetLength(0); if (load < 0) { mp.Monstats = sav.Monstats; monstatsLength = sav.Monstats.GetLength(0); Array.Copy(sav.PlayerStats, mp.StartnEnd, 2); playerhp = sav.PlayerStats[2]; Array.Copy(sav.PlayerStats, 3, playerdp, 0, 2); Array.Copy(sav.PlayerStats, 5, playerarmor, 0, 3); } //Set up the player collection.player = new PlayerEntity("player", mp.StartnEnd[0], mp.StartnEnd[1], playerhp, playerdp[0], playerdp[1], playerarmor[0], playerarmor[1], playerarmor[2]); //Set up monsters for (int i = 0; i < monstatsLength; i++) { string monstertype = ("monster " + mp.Monstats[i, 0]); MonsterEntity monster = new MonsterEntity(monstertype, mp.Monstats[i, 1], mp.Monstats[i, 2], mp.Monstats[i, 3], mp.Monstats[i, 4], mp.Monstats[i, 5]); collection.monsters.Add(monster); } //Set up Items if (load < 0) { foreach (int i in sav.itemused) { { string itemtype = ("item " + mp.itemstats[i, 0]); ItemEntity item = new ItemEntity(itemtype, mp.itemstats[i, 1], mp.itemstats[i, 2], mp.itemstats[i, 0], mp.itemstats[i, 3], false, i); collection.items.Add(item); } } } else { for (int i = 0; i < mp.itemstats.GetLength(0); i++) { string itemtype = ("item " + mp.itemstats[i, 0]); ItemEntity item = new ItemEntity(itemtype, mp.itemstats[i, 1], mp.itemstats[i, 2], mp.itemstats[i, 0], mp.itemstats[i, 3], false, i); collection.items.Add(item); } } //Set up triggers collection.nextLevelTrigger = new TriggerEntity("End", mp.StartnEnd[2], mp.StartnEnd[3], LoadNextLevel); if (collection.level == 0) { collection.triggers.Add(new TriggerEntity("trigger", 6, 7, new Action <object>(MainViewModel.StartGameCommand.Execute), 1, "New\nGame", true)); collection.triggers.Add(new TriggerEntity("trigger", 5, 7, new Action <object>(MainViewModel.StartGameCommand.Execute), 1, "New\nGame", true)); collection.triggers.Add(new TriggerEntity("trigger", 1, 7, new Action <object>(MainViewModel.StartGameCommand.Execute), -1, "Load\nSlot 1", MainViewModel.StartGameCommand.CanExecute(-1))); collection.triggers.Add(new TriggerEntity("trigger", 3, 7, new Action <object>(MainViewModel.StartGameCommand.Execute), -2, "Load\nSlot 2", MainViewModel.StartGameCommand.CanExecute(-2))); collection.triggers.Add(new TriggerEntity("trigger", 2, 10, new Action <object>(MainViewModel.StartGameCommand.Execute), -3, "Load\nSlot 3", MainViewModel.StartGameCommand.CanExecute(-3))); collection.triggers.Add(new TriggerEntity("trigger", 8, 7, new Action <object>(MainViewModel.StartGameCommand.Execute), -4, "Load\nSlot 4", MainViewModel.StartGameCommand.CanExecute(-4))); collection.triggers.Add(new TriggerEntity("trigger", 10, 7, new Action <object>(MainViewModel.StartGameCommand.Execute), -5, "Load\nSlot 5", MainViewModel.StartGameCommand.CanExecute(-5))); } }
public void SetMonsterEntity(MonsterEntity monster) { m_MonsterEntity = monster; }
/// <summary> /// Creates the AI tree. /// </summary> /// <returns>The AI tree.</returns> /// <param name="szBlueprintFile">Size blueprint file.</param> public AIBehaviourTree CreateAITree(MonsterEntity monster, string szBlueprintFile) { if (!string.IsNullOrEmpty(szBlueprintFile)) { TextAsset asset = Resources.Load<TextAsset>(szBlueprintFile); if (!asset) throw new System.NullReferenceException(); // create the monster ai tree return AIBehaviourTreeManager.GetSingleton().CreateAIBehaviourTree( monster.EntityID, new AIEntityContext(monster), asset.text); } return default(AIBehaviourTree); }
private void Monster_ImageLoaded(Entity entity) { MonsterEntity monster = (MonsterEntity)entity; monster.InitializeAnimationsAsDefault(); }