void OnTriggerStay(Collider other) { if (isMagicable == true) { isMagicable = false; Hero hero = other.gameObject.GetComponent <Hero> (); if (hero != null) { // 改变金币 if (magicWaterData.AddGold != 0) { int gold = PlayerData.Gold; if (magicWaterData.AddGold < 0 && gold < Mathf.Abs(magicWaterData.AddGold)) { return; } GameEntry.Setting.SetInt(Constant.Player.Gold, gold + magicWaterData.AddGold); GameEntry.Event.Fire(this, ReferencePool.Acquire <RefreshGoldEventArgs> ()); } // 改变血量 if (magicWaterData.AddHPPercent != 0 && Mathf.Abs((int)(hero.HeroData.MaxHP * magicWaterData.AddHPPercent)) > Mathf.Abs(magicWaterData.AddHP)) { hero.OnDamage(-magicWaterData.AddHPPercent, true); } else if (magicWaterData.AddHP != 0) { hero.OnDamage(-magicWaterData.AddHP, true); } // 改变攻击 if (magicWaterData.AddAtk != 0) { hero.PowerUpByAbsValue(0, 0, magicWaterData.AddAtk, 0); } // 生成克隆英雄 if (magicWaterData.CreateCloneHeroTypeID != 0) { MonsterData monsterData = new MonsterData( EntityExtension.GenerateSerialId(), magicWaterData.CreateCloneHeroTypeID, CampType.CloneHero, 0); monsterData.Position = new Vector3(transform.position.x, 0, transform.position.z); // 避免克隆英雄太弱,根据玩家英雄实时最大血量调整克隆英雄属性 float powerPercent = hero.HeroData.MaxHP / monsterData.MaxHP / 100f + 1; monsterData.AjustPower(powerPercent); EntityExtension.ShowMonster(typeof(Monster), "MonsterGroup", monsterData); } } } }
protected override void OnUpdate(float elapseSeconds, float realElapseSeconds) { base.OnUpdate(elapseSeconds, realElapseSeconds); timeCounter += elapseSeconds; pastTime += elapseSeconds; if (pastTime < monsterCreaterData.StartTime) { return; } // 第一个创建的怪物跳过创建间隔 if (createNum > 0 && timeCounter < monsterCreaterData.Interval) { return; } timeCounter = 0; // 创建怪物 if (Utility.Random.GetRandom(100) < monsterCreaterData.Probability) { for (int i = 0; i < monsterCreaterData.PerNum; i++) { CampType camp = CampType.Enemy; MonsterData monsterData = new MonsterData( EntityExtension.GenerateSerialId(), monsterCreaterData.MonsterTypeId, camp, monsterCreaterData.MonsterPrize); monsterData.Position = new Vector3(Utility.Random.GetRandom(5, 25), 0, Utility.Random.GetRandom(5, 25)); // 调整怪物属性 monsterData.AjustPower(monsterCreaterData.PowerPercent); monsterData.ChangeName(monsterCreaterData.Name); EntityExtension.ShowMonster(typeof(Monster), "MonsterGroup", monsterData); createNum++; } // 达到最大创建数量,销毁生成器 if (createNum >= monsterCreaterData.MaxNum) { GameEntry.Entity.HideEntity(this.Id); } } }