protected override void OnExecute(CGGameMode gameMode, ref EventExeucteResult outError)…
- User
protected override void OnExecute(CGGameMode gameMode, ref EventExeucteResult outError) { Card cardObject = gameMode.GetActorObject(m_minion); Player playerObject = gameMode.GetActorObject(cardObject.GetOwnerPlayer()); BattleField battleField = gameMode.GetBattleFieldObject(playerObject.GetPlayerPosition());
if (playerObject.PveItems.HasFlag(PVEItem.BloodPayment) && !playerObject.HasBloodPaymented) { Hero hero = gameMode.GetActorObject(playerObject.GetHero()); GameAttribute health = hero.GetHealth(); health -= cardObject.GetCost().Value; hero.SetHealth(health); playerObject.HasBloodPaymented = true; } else { if (m_isSacrifice) { ActorRef<Card>? result = battleField.GetMinionCard(m_destPosition.SubPosition); Card sacrificeCard = gameMode.GetActorObject(result.Value); PlayerCost curValue = playerObject.GetPlayerCost(); // 献祭场景下吸收献祭卡一半的费用 curValue.Value.Value += sacrificeCard.GetSacrificeCostValue(); // 花费自身的费用 curValue.Value.Value -= cardObject.GetCost().Value.Value.intValue; playerObject.SetPlayerCost(curValue); gameMode.MoveCardToGraveDeck(sacrificeCard); cardObject.SetTribute(sacrificeCard); } else { CGGivePlayerCostEvent giveCostEvent = new CGGivePlayerCostEvent(); giveCostEvent.Player = cardObject.GetOwnerPlayer(); giveCostEvent.Delta = -cardObject.GetCost(); giveCostEvent.Execute(gameMode); } } CGGameMode.MoveCardIn moveCardParam = new CGGameMode.MoveCardIn { Card = m_minion, DestPosition = new AccurateCardPosition(m_destPosition) }; gameMode.MoveCard(moveCardParam); cardObject.SetIsDeployed(false); cardObject.DeployTimer.Start(gameMode, gameMode.GameConfig.MinionDeployGCD, 1); gameMode.OnAfterCardDeployedHandle?.Invoke(cardObject); cardObject.OnSoundPlayed(DamageAudioType.Deploy); if (playerObject.PveItems.HasFlag(PVEItem.Phantom)) { cardObject.EnterAmbushTimer.Start(gameMode, GameTimeSpan.OneSecond * 3); } if (cardObject.HasEffect(CardKeyWordType.Expose) || cardObject.HasEffect(CardKeyWordType.CopyExpose)) { PlayerPosition oppoPosition = gameMode.GetOppositePlayerPosition(playerObject.GetPlayerPosition()); TrapField trapField = gameMode.GetTrapFieldObject(oppoPosition); List<Card> deployedTrapCards = trapField.GetDeployedCardObjects().ToList(); foreach (var card in deployedTrapCards) { if (card.HasEffect(CardKeyWordType.CounterExpose)) { CGCastTrapCardToPositionEvent cardEvent = new CGCastTrapCardToPositionEvent { Card = gameMode.GetActor(card), Player = gameMode.GetPlayer(oppoPosition).Value, TargetCards = new List<ActorRef<Card>> { m_minion } }; cardEvent.Execute(gameMode); return; } } if (!cardObject.HasDamageEffect()) { cardObject.OnSoundPlayed(DamageAudioType.MinionNoDamage); } } if (cardObject.HasEffect(CardKeyWordType.Expose)) { gameMode.AddStatusData(cardObject.GetOwnerPlayer(), StatusType.ExposeMinion, 1); } if (cardObject.HasEffect(CardKeyWordType.Cycle)) { gameMode.AddStatusData(cardObject.GetOwnerPlayer(), StatusType.CycleMinion, 1); } if (cardObject.HasEffect(CardKeyWordType.Expose)) { foreach (var effect in cardObject.GetCardAllEffectsByKeyword(CardKeyWordType.Expose)) { foreach (var triggerEffect in effect.triggerEffects) { ExecuteLuaSingleTarget(gameMode, triggerEffect, cardObject); } } for (int i = 0; i < playerObject.GetExtraExposeTimes(); i++) { foreach (var effect in cardObject.GetCardAllEffectsByKeyword(CardKeyWordType.Expose)) { foreach (var triggerEffect in effect.triggerEffects) { ExecuteLuaSingleTarget(gameMode, triggerEffect, cardObject); } } } if (!playerObject.GetIsAlwaysDoubleExpose()) { if (playerObject.GetExtraExposeCount() > 0) { int count = playerObject.GetExtraExposeCount(); count--; playerObject.SetExtraExposeCount(count); // 使用完次数后清除双倍战吼效果 if (count == 0) { playerObject.SetExtraExposeTimes(0); } } else { playerObject.SetExtraExposeTimes(0); } } VisualEffect visualEffect = new VisualEffect { Name = "UniversalDebut", SpineType = SpineType.Single, LifeTime = 1f, Actors = new List<IActor> { cardObject } }; gameMode.Trigger(cardObject, CGEventNames.OnAfterEffectExecute, visualEffect); } if (cardObject.HasEffect(CardKeyWordType.CopyExpose)) { HandCardDeck handCardDeck = gameMode.GetActorObject(playerObject.GetHandCardDeck()); if (handCardDeck.HasOtherPlayerCard()) { foreach (var effect in cardObject.GetCardAllEffectsByKeyword(CardKeyWordType.CopyExpose)) { foreach (var triggerEffect in effect.triggerEffects) { ExecuteLuaSingleTarget(gameMode, triggerEffect, cardObject); } } for (int i = 0; i < playerObject.GetExtraExposeTimes(); i++) { foreach (var effect in cardObject.GetCardAllEffectsByKeyword(CardKeyWordType.CopyExpose)) { foreach (var triggerEffect in effect.triggerEffects) { ExecuteLuaSingleTarget(gameMode, triggerEffect, cardObject); } } } if (!playerObject.GetIsAlwaysDoubleExpose()) { if (playerObject.GetExtraExposeCount() > 0) { int count = playerObject.GetExtraExposeCount(); count--; playerObject.SetExtraExposeCount(count); // 使用完次数后清除双倍战吼效果 if (count == 0) { playerObject.SetExtraExposeTimes(0); } } else { playerObject.SetExtraExposeTimes(0); } } VisualEffect visualEffect = new VisualEffect { Name = "UniversalDebut", SpineType = SpineType.Single, LifeTime = 1f, Actors = new List<IActor> { cardObject } }; gameMode.Trigger(cardObject, CGEventNames.OnAfterEffectExecute, visualEffect); } } if (m_isSacrifice && cardObject.HasEffect(CardKeyWordType.SacrificeTrigger)) { foreach (var effect in cardObject.GetCardAllEffectsByKeyword(CardKeyWordType.SacrificeTrigger)) { foreach (var triggerEffect in effect.triggerEffects) { ExecuteLuaSingleTarget(gameMode, triggerEffect, cardObject); } } } HeroTalent heroTalent = gameMode.GetActorObject(playerObject.GetHeroTalent()); if (!cardObject.GetOwnerPlayer().IsSameWith(cardObject.GetOriginOwner())) { if (heroTalent.GetTalentType() == HeroTypes.Marauder && heroTalent.GetTalentIndex() == 0) { gameMode.MarauderTalent0(cardObject); } gameMode.OnAfterUseStealCardHandler?.Invoke(cardObject); } if (heroTalent.GetTalentType() == HeroTypes.Strategist && heroTalent.GetTalentIndex() == 0) { gameMode.StrategistTalent0(cardObject, m_minion); } // 部署的镜像也进行天赋计数 if (cardObject.GetName().Equals("镜像")) { gameMode.MageEnergyDrainTalent(cardObject, true); } } 帮忙优化一下这段代码 - Assistant
- User
hero 没有DecrementHealth 这个方法
- Assistant
If the
Heroclass doesn't have aDecrementHealthmethod, you can directly manipulate the health attribute in the method. Assuming thatGetHealth()returns a mutable type or if there's a setter method available, you can adjust the player's health like this:Refactored Code with Health Adjustment
private void ProcessBloodPaymentIfApplicable(CGGameMode gameMode, Card cardObject, Player playerObject) { if (playerObject.PveItems.HasFlag(PVEItem.BloodPayment) && !playerObject.HasBloodPaymented) { Hero hero = gameMode.GetActorObject(playerObject.GetHero()); GameAttribute health = hero.GetHealth(); health.Value -= cardObject.GetCost().Value; // Adjust health directly hero.SetHealth(health); // Assuming SetHealth is the method to update health in the Hero class playerObject.HasBloodPaymented = true; } } - User
PlayerCost 也没有IncreaseValue 和DecreaseValue方法
- Assistant
If the
PlayerCostobject lacks specific methods likeIncreaseValueandDecreaseValue, you'll need to adjust the cost directly. Assuming thatPlayerCosthas a modifiable property for the value, you can increment and decrement directly on that property.Here's how you can refactor the code to adjust the player cost correctly:
Refactored Code for Adjusting Player Cost
private void HandleSacrifice(CGGameMode gameMode, Card cardObject, BattleField battleField, Player playerObject) { ActorRef<Card>? result = battleField.GetMinionCard(m_destPosition.SubPosition); if (result is ActorRef<Card> sacrificeRef) { Card sacrificeCard = gameMode.GetActorObject(sacrificeRef); PlayerCost curValue = playerObject.GetPlayerCost(); // Assuming curValue.Value is directly modifiable curValue.Value.Value += sacrificeCard.GetSacrificeCostValue(); curValue.Value.Value -= cardObject.GetCost().Value.intValue; playerObject.SetPlayerCost(curValue); gameMode.MoveCardToGraveDeck(sacrificeCard); cardObject.SetTribute(sacrificeCard); } } - User
点地板的音效 请翻译
- Assistant
"Pointing to the floor sound effect" can be translated into Chinese as "指向地板的音效".
- User
炉石点击地板,空地,表达这种意思,用什么短语比较好
- Assistant
在《炉石传说》中,描述点击或选择空白区域或没有特定目标的地方,常用的短语是“点击空地”或“点击地板”。这些表达方式传达了在界面上进行无特定对象操作的意图。例如,你可以说“在游戏中点击空地以取消选择”。
- User
用英语怎么表达?
- Assistant
In English, you would typically say "clicking on empty space" or "clicking on the ground" to express the action of clicking on an area that doesn't have a specific target or object in games like Hearthstone. This conveys the idea of interacting with a neutral area of the game interface.
- User
if (Input.GetMouseButton(0)) { if (!EventSystem.current.IsPointerOverGameObject() && m_ClickGround!= null) { // 检查音频源是否正在播放 if (!m_ClickGround.isPlaying) { m_ClickGround.Play(); } } } 好像点击到gameobject还是会发出声音
- Assistant
The current implementation seems to cause the sound to play even when clicking on a game object. This likely indicates an issue with how you're checking whether the pointer is over a UI object. The
EventSystem.current.IsPointerOverGameObject()method checks if the pointer is over a UI element, but not necessarily over any non-UI GameObject. - User
可以加一下日志打印出来,如果Physics.Raycast(ray, out hit) 这个为true的时候,碰到了什么gameobject
- Assistant
Sure, you can add logging to print the name of the GameObject that the raycast hits. This is useful for debugging to see which objects are being clicked on. Here's how you can modify the code to include logging:
using UnityEngine; using UnityEngine.EventSystems; public class ClickHandler : MonoBehaviour { public AudioSource m_ClickGround; void Update() { if (Input.GetMouseButton(0)) { // Check if the pointer is not over a UI element if (!EventSystem.current.IsPointerOverGameObject()) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; // Perform a raycast if (Physics.Raycast(ray, out hit)) { // Log the name of the GameObject that was hit Debug.Log("Hit GameObject: " + hit.collider.gameObject.name); } else { // No objects were hit, safe to play ground sound if (m_ClickGround != null && !m_ClickGround.isPlaying) { m_ClickGround.Play(); } } } } } } - User
emm,发现点击到了active 为flase的gameobject Physics.Raycast(ray, out hit)也为true了,要排除掉这些gameobject的
- Assistant
To exclude inactive GameObjects from being considered in raycasting, you must check if the GameObject that was hit by the raycast is active. Unity's physics system will still detect colliders on inactive GameObjects if they're enabled at the component level but not necessarily active in the hierarchy. Here’s how you can modify the logic to account for this:
- User
如何排除一些虽然active但是看不见的gameobject呢
- Assistant