Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 00023 00024 00025 00026 00027 00028 00029 00030 00031 00032 00033 00034 00035 00036 00037 00038 00039 00040 00041 00042 00043 00044 00045 00046 00047 00048 00049 00050 00051 00052 00053 00054 00055 00056 00057 00058 00059 00060 00061 00062 00063 00064 00065 00066 00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095 00096 00097 00098 00099 00100 00101 00102 00103 00104 00105 00106 00107 00108 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127 00128 00129 00130 00131 00132 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00146 |
class Shield extends Engine.Actor native; var float health; var float offlineSeconds; var() float max "The number of hitpoints that the shield has"; var() float rechargeRate "Number of health points that the shield regenerates per second"; var() float offlineSecondsScale "Number of seconds that the shield stays disabled for when energy is depleted: offline seconds = damage * offlineSecondsScale"; var() float maxOfflineSeconds "The maximum number of seconds that the shield can stay disabled for in response to damage"; // shield effect var() Material effectMaterial "Overlay material when shield takes a hit"; var() float effectDisplayTime "How long the shield effect is displayed for after a hit"; var bool bActive; var float clientHealth; var float shieldEffectTime; replication { reliable if (ROLE == ROLE_Authority) health; } function PostBeginPlay() { health = max; Super.PostBeginPlay(); } simulated function PostNetBeginPlay() { clientHealth = health; shieldEffectTime = 0; } simulated function PostNetReceive() { if (Level.NetMode == NM_Client && clientHealth != health) { if (health < clientHealth) triggerDamageEffect(); clientHealth = health; } } simulated function triggerDamageEffect() { // TBD: it would be cool to have a different damage effect when the shield goes offline shieldEffectTime = effectDisplayTime; } simulated function updateDamageEffect(float Delta) { shieldEffectTime -= Delta; if (shieldEffectTime < 0) shieldEffectTime = 0; } simulated function Tick(float Delta) { recharge(Delta); updateDamageEffect(Delta); } simulated function bool EffectActive() { return (shieldEffectTime > 0); } simulated native function Material GetEffectMaterial(); function recharge(float Delta) { if (!bActive) return; // recharge shield if (offlineSeconds > 0) { offlineSeconds -= Delta; } else if (health < max) { health += rechargeRate * Delta; if (health > max) health = max; } } // Applies damage. Any damage not done to shields is returned as overflow. function int applyDamage(float Damage, float otherHealth) { local int overflow; if (!active()) return Damage; health -= Damage; if (health < 0) { overflow = -health; if (health <= 0 && health > -1) health = -1; offlineSeconds = -otherHealth * offlineSecondsScale; FClamp(offlineSeconds, 0, maxOfflineSeconds); } // servers and sp trigger damage fx here. clients trigger it on PostNetReceive if (Damage > 0 && Level.NetMode != NM_Client) triggerDamageEffect(); return overflow; } function activate() { bActive = true; } function deactivate() { health = 0; bActive = false; } function bool active() { return health > 0 && bActive; } defaultproperties { DrawType = DT_None RemoteRole = ROLE_SimulatedProxy bActive = true bNetNotify = true rechargeRate = 3 max = 50 effectDisplayTime = 0.3 effectMaterial = Material'BaseObjects.ResupplyStationLum' } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |