4 static protected const string SEL_CLIPS_CAR =
"clips_car_battery";
5 static protected const string SEL_CLIPS_TRUCK =
"clips_truck_battery";
6 static protected const string SEL_CLIPS_DETACHED =
"clips_detached";
7 static protected const string SEL_CLIPS_FOLDED =
"clips_folded";
8 static protected const string SEL_SWITCH_ON =
"switch_on";
9 static protected const string SEL_SWITCH_OFF =
"switch_off";
10 static protected const string SEL_CORD_PLUGGED =
"cord_plugged";
11 static protected const string SEL_CORD_FOLDED =
"cord_folded";
12 static protected const string SEL_LIGHT_STATE_1 =
"light_stand_by";
13 static protected const string SEL_LIGHT_STATE_2 =
"light_charging";
14 static protected const string SEL_LIGHT_STATE_3 =
"light_charged";
17 static protected const string RED_LIGHT_GLOW =
"dz\\gear\\camping\\data\\battery_charger_light_r.rvmat";
18 static protected const string GREEN_LIGHT_GLOW =
"dz\\gear\\camping\\data\\battery_charger_light_g.rvmat";
19 static protected const string YELLOW_LIGHT_GLOW =
"dz\\gear\\camping\\data\\battery_charger_light_y.rvmat";
20 static protected const string SWITCH_LIGHT_GLOW =
"dz\\gear\\camping\\data\\battery_charger_light_switch_on.rvmat";
21 static protected const string DEFAULT_MATERIAL =
"dz\\gear\\camping\\data\\battery_charger.rvmat";
23 protected const string ATTACHED_CLIPS_STATES[] = {SEL_CLIPS_CAR, SEL_CLIPS_TRUCK};
24 protected const int ATTACHED_CLIPS_STATES_COUNT = 2;
28 int m_BatteryEnergy0To100;
29 protected float m_ChargeEnergyPerSecond;
31 static protected float m_BlinkingStatusLightInterval = 0.4;
32 ref
Timer m_UpdateStatusLightsTimer;
33 protected bool m_BlinkingStatusLightIsOn =
false;
37 m_ChargeEnergyPerSecond =
GetGame().ConfigGetFloat (
"CfgVehicles " +
GetType() +
" ChargeEnergyPerSecond");
40 RegisterNetSyncVariableInt(
"m_BatteryEnergy0To100");
41 RegisterNetSyncVariableBool(
"m_IsSoundSynchRemote");
42 RegisterNetSyncVariableBool(
"m_IsPlaceSound");
45 override bool IsElectricAppliance()
50 override void OnWork(
float consumed_energy )
59 float battery_capacity = battery.GetCompEM().GetEnergyMax();
61 if ( battery.GetCompEM().GetEnergy() < battery_capacity )
65 battery.SetTemperature(60);
67 float charger_health = GetHealth(
"",
"");
68 float energy_add = m_ChargeEnergyPerSecond * ( consumed_energy / GetCompEM().GetEnergyUsage() );
71 if (FeatureTimeAccel.GetFeatureTimeAccelEnabled(ETimeAccelCategories.ENERGY_RECHARGE))
73 float timeAccel = FeatureTimeAccel.GetFeatureTimeAccelValue();
74 energy_add *= timeAccel;
78 if ( GetCompEM().ConsumeEnergy(energy_add) )
81 energy_add = energy_add * ( 0.5 + charger_health*0.005 );
89 battery.GetCompEM().AddEnergy( energy_add );
93 battery.GetCompEM().SetEnergy( battery_capacity );
95 m_BatteryEnergy0To100 = battery.GetCompEM().GetEnergy0To100();
105 UpdateStatusLights();
106 m_UpdateStatusLightsTimer.Run( m_BlinkingStatusLightInterval/2 ,
this,
"UpdateStatusLights", NULL,
true);
114 UpdateStatusLights();
115 m_UpdateStatusLightsTimer.Stop();
119 void UpdateStatusLights()
123 if (GetCompEM().IsWorking())
132 if (m_BatteryEnergy0To100 <= 33)
136 if (m_BlinkingStatusLightIsOn)
141 m_BlinkingStatusLightIsOn = !m_BlinkingStatusLightIsOn;
143 else if (m_BatteryEnergy0To100 > 33 && m_BatteryEnergy0To100 <= 66)
149 else if (m_BatteryEnergy0To100 > 66 && m_BatteryEnergy0To100 < 100)
155 if (m_BlinkingStatusLightIsOn)
160 m_BlinkingStatusLightIsOn = !m_BlinkingStatusLightIsOn;
162 else if (m_BatteryEnergy0To100 >= 100)
171 if (m_BlinkingStatusLightIsOn)
176 m_BlinkingStatusLightIsOn = !m_BlinkingStatusLightIsOn;
194 if( !super.CanPutInCargo(parent) ) {
return false;}
196 if ( !GetCompEM().IsPlugged() && !GetCompEM().GetPluggedDevice() )
206 if( !super.CanPutIntoHands( parent ) )
211 if ( !GetCompEM().IsPlugged() && !GetCompEM().GetPluggedDevice() )
219 override void OnOwnSocketTaken(
EntityAI device )
221 string att_type = device.GetType();
223 if ( att_type ==
"CarBattery" )
225 HideAttachedClipsStates();
226 ShowSelection(SEL_CLIPS_CAR);
229 if ( att_type ==
"TruckBattery" )
231 HideAttachedClipsStates();
232 ShowSelection(SEL_CLIPS_TRUCK);
235 HideSelection(SEL_CLIPS_DETACHED);
236 HideSelection(SEL_CLIPS_FOLDED);
239 override void OnOwnSocketReleased(
EntityAI device )
241 HideAttachedClipsStates();
242 ShowSelection(SEL_CLIPS_DETACHED);
247 if ( !super.CanReceiveAttachment(attachment, slotId) )
251 Class.CastTo(ibase, attachment);
259 if ( GetCompEM().GetPluggedDevice() )
262 if ( ibase.HasEnergyManager() && ibase.GetCompEM().GetPluggedDevicesCount() >= 1 )
270 if ( !super.CanLoadAttachment(attachment) )
274 Class.CastTo(ibase, attachment);
277 if ( GetCompEM().GetPluggedDevice() )
280 if ( ibase.HasEnergyManager() && ibase.GetCompEM().GetPluggedDevicesCount() >= 1 )
286 void HideAttachedClipsStates()
288 for (
int i = 0; i < ATTACHED_CLIPS_STATES_COUNT; i++ )
290 string selection = ATTACHED_CLIPS_STATES[i];
291 HideSelection(selection);
301 SetObjectMaterial( 0, RED_LIGHT_GLOW );
305 SetObjectMaterial( 2, GREEN_LIGHT_GLOW );
309 SetObjectMaterial( 1, YELLOW_LIGHT_GLOW );
313 SetObjectMaterial( 3, SWITCH_LIGHT_GLOW );
318 SetObjectMaterial( 0, DEFAULT_MATERIAL );
322 SetObjectMaterial( 2, DEFAULT_MATERIAL );
324 void YellowLightOff()
326 SetObjectMaterial( 1, DEFAULT_MATERIAL );
328 void SwitchLightOff()
330 SetObjectMaterial( 3, DEFAULT_MATERIAL );
334 override void OnSwitchOn()
336 HideSelection(SEL_SWITCH_OFF);
337 ShowSelection(SEL_SWITCH_ON);
340 override void OnSwitchOff()
342 HideSelection(SEL_SWITCH_ON);
343 ShowSelection(SEL_SWITCH_OFF);
349 super.OnInventoryExit(player);
351 HideAttachedClipsStates();
352 HideSelection(SEL_CLIPS_FOLDED);
353 ShowSelection(SEL_CLIPS_DETACHED);
358 super.OnInventoryEnter(player);
360 HideAttachedClipsStates();
361 HideSelection(SEL_CLIPS_DETACHED);
362 ShowSelection(SEL_CLIPS_FOLDED);
367 super.OnVariablesSynchronized();
377 super.RefreshPhysics();
381 RemoveProxyPhysics(
"battery" );
382 AddProxyPhysics(
"battery" );
385 RemoveProxyPhysics(
"battery" );
394 super.OnPlacementStarted(player);
396 SetAnimationPhase(SEL_CLIPS_DETACHED, 0);
397 SetAnimationPhase(SEL_CLIPS_FOLDED, 1);
398 SetAnimationPhase(SEL_SWITCH_ON, 1);
399 SetAnimationPhase(SEL_SWITCH_OFF, 1);
400 SetAnimationPhase(SEL_LIGHT_STATE_1, 1);
401 SetAnimationPhase(SEL_LIGHT_STATE_2, 1);
402 SetAnimationPhase(SEL_LIGHT_STATE_3, 1);
412 foreach (
string selection : selections)
415 playerPB.GetHologramServer().SetSelectionToRefresh(selection);
417 playerPB.GetHologramLocal().SetSelectionToRefresh(selection);
423 super.OnPlacementComplete( player, position, orientation );
435 return "placeBatteryCharger_SoundSet";