XG-Proyect-v3.x.x icon indicating copy to clipboard operation
XG-Proyect-v3.x.x copied to clipboard

Combat Report Generation Error

Open OceanicNomad opened this issue 1 year ago • 4 comments

These changed will produce a correct combat report instead of a server error.

https://github.com/XGProyect/XG-Proyect-v3.x.x/blob/d1d9dc7ed498c4417f41b955871d4b67e0bb39d7/app/Libraries/BattleEngine/Core/BattleReport.php#L259 _DEBRIS_FACTOR needs to be changed to SHIPS_DEBRIS_FACTOR

https://github.com/XGProyect/XG-Proyect-v3.x.x/blob/d1d9dc7ed498c4417f41b955871d4b67e0bb39d7/app/Libraries/BattleEngine/Core/BattleReport.php#L281 _DEBRIS_FACTOR needs to be changed to DEFENCE_DEBRIS_FACTOR

OceanicNomad avatar Aug 16 '23 19:08 OceanicNomad

Thanks for the suggested fix.

Can you elaborate on how the code should look like?

I have tried the changes in the following way:

  1. Setting Line 259 up so it comes out to "SHIPS_DEBRIS_FACTOR" (done the same with the defence one in 281)
  2. setting up the line so it looks like $factor = 'SHIPS_DEBRIS_FACTOR'; and $factor = 'DEFENCE_DEBRIS_FACTOR'; (both changes had the same outcome)

Everything I tried did not resolve the battle report issue and resulted in some kind of server error being thrown.

I´ll attach some screenshots with info of the server and the error here. image image

Let me know if anyone needs more Info. I´ll gladly provide it.

w503v12 avatar Oct 26 '23 13:10 w503v12

Hi @w503v12, can you send me the code you have changed in your app/Libraries/BattleEngine/Core/BattleReport.php

It looks like you have made an incorrect adjustment which is why you are getting the error to an undefined constant as the file doesn't exist.

OceanicNomad avatar Oct 26 '23 13:10 OceanicNomad

Sure. So I tried different things, I´ll just list them all.

Version 1: public function getAttackerDebris() { $sendMetal = 0; $sendCrystal = 0; foreach ($this->getAttackersLostUnits(!REPAIRED_DO_DEBRIS) as $idPlayer => $player) { foreach ($player as $idFleet => $fleet) { foreach ($fleet as $role => $values) { $metal = 0; $crystal = 0; foreach ($values as $idShipType => $lost) { $metal += $lost[0]; $crystal += $lost[1]; } $factor = constant(strtoupper($role) . 'S_DEBRIS_FACTOR'); $sendMetal += $metal * $factor; $sendCrystal += $crystal * $factor; } } } return [$sendMetal, $sendCrystal]; }

Changed it because this comes out as "SHIPS_DEBRIS_FACTOR".

Version 2:

public function getAttackerDebris() { $sendMetal = 0; $sendCrystal = 0; foreach ($this->getAttackersLostUnits(!REPAIRED_DO_DEBRIS) as $idPlayer => $player) { foreach ($player as $idFleet => $fleet) { foreach ($fleet as $role => $values) { $metal = 0; $crystal = 0; foreach ($values as $idShipType => $lost) { $metal += $lost[0]; $crystal += $lost[1]; } $factor = constant(strtoupper($role) . 'SHIPS_DEBRIS_FACTOR'); $sendMetal += $metal * $factor; $sendCrystal += $crystal * $factor; } } } return [$sendMetal, $sendCrystal]; }

This generates a server error with "SHIPSHIPS_DEBRIS_ERROR" listed, looks like it actually fills in "ship" kinda correctly but not "SHIPS"

The defence line does not produce any server errors, but I list the way I tried it anyways:

public function getDefenderDebris() { $sendMetal = 0; $sendCrystal = 0; foreach ($this->getDefendersLostUnits(!REPAIRED_DO_DEBRIS) as $idPlayer => $player) { foreach ($player as $idFleet => $fleet) { foreach ($fleet as $role => $values) { $metal = 0; $crystal = 0; foreach ($values as $idShipType => $lost) { $metal += $lost[0]; $crystal += $lost[1]; } $factor = constant(strtoupper($role) . 'DEFENCE_DEBRIS_FACTOR'); $sendMetal += $metal * $factor; $sendCrystal += $crystal * $factor; } } } return [$sendMetal, $sendCrystal]; }

I´m not that good at PHP so I´ll take any pointers I can get.

Thank you for looking at it!

w503v12 avatar Oct 26 '23 15:10 w503v12

[FIX] https://github.com/XGProyect/XG-Proyect-v3.x.x/issues/595

jonamix-ar avatar Feb 13 '24 01:02 jonamix-ar