-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from insthync/1.23
1.23
- Loading branch information
Showing
7 changed files
with
384 additions
and
239 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
<?php | ||
function RandomFortuneWheelReward($fortuneWheel) | ||
{ | ||
$rewards = $fortuneWheel['rewards']; | ||
$generatedResult = array(); | ||
$generatedWeight = array(); | ||
$countRewards = count($rewards); | ||
for ($i = 0; $i < $countRewards; ++$i) | ||
{ | ||
$reward = $rewards[$i]; | ||
$id = '_' . $i; | ||
$generatedResult[$id] = $reward; | ||
$generatedResult[$id]['rewardIndex'] = $i; | ||
$generatedWeight[$id] = $reward['randomWeight']; | ||
} | ||
|
||
$takenId = WeightedRandom($generatedWeight, 0); | ||
if ($takenId) { | ||
return $generatedResult[$takenId]; | ||
} | ||
return NULL; | ||
} | ||
|
||
function GetAvailableFortuneWheelList() | ||
{ | ||
$list = array(); | ||
$gameData = \Base::instance()->get('GameData'); | ||
$fortuneWheels = $gameData['fortuneWheels']; | ||
foreach ($fortuneWheels as $key => $value) { | ||
$list[] = $key; | ||
} | ||
$output = array('error' => ''); | ||
$output['list'] = $list; | ||
echo json_encode($output); | ||
} | ||
|
||
function SpinFortuneWheel($fortuneWheelDataId) | ||
{ | ||
$gameData = \Base::instance()->get('GameData'); | ||
$output = array('error' => ''); | ||
$player = GetPlayer(); | ||
$playerId = $player->id; | ||
|
||
$fortuneWheel = $gameData['fortuneWheels'][$fortuneWheelDataId]; | ||
if (!$fortuneWheel) { | ||
$output['error'] = 'ERROR_INVALID_FORTUNE_WHEEL_DATA'; | ||
} else { | ||
$softCurrency = GetCurrency($playerId, $gameData['softCurrencyId']); | ||
$hardCurrency = GetCurrency($playerId, $gameData['hardCurrencyId']); | ||
|
||
$rewardIndex = 0; | ||
$rewardItems = array(); | ||
$createItems = array(); | ||
$updateItems = array(); | ||
$deleteItemIds = array(); | ||
$updateCurrencies = array(); | ||
$requirementType = $fortuneWheel['requirementType']; | ||
$price = $fortuneWheel['price']; | ||
if ($requirementType == ELootboxRequirementType::SoftCurrency && $price > $softCurrency->amount) { | ||
$output['error'] = 'ERROR_NOT_ENOUGH_SOFT_CURRENCY'; | ||
} else if ($requirementType == ELootboxRequirementType::HardCurrency && $price > $hardCurrency->amount) { | ||
$output['error'] = 'ERROR_NOT_ENOUGH_HARD_CURRENCY'; | ||
} else { | ||
switch ($requirementType) | ||
{ | ||
case ELootboxRequirementType::SoftCurrency: | ||
$softCurrency->amount -= $price; | ||
$softCurrency->update(); | ||
$updateCurrencies[] = $softCurrency; | ||
break; | ||
case ELootboxRequirementType::HardCurrency: | ||
$hardCurrency->amount -= $price; | ||
$hardCurrency->update(); | ||
$updateCurrencies[] = $hardCurrency; | ||
break; | ||
} | ||
|
||
$reward = RandomFortuneWheelReward($fortuneWheel); | ||
if ($reward) | ||
{ | ||
$rewardIndex = $reward['rewardIndex']; | ||
|
||
// Soft currency | ||
$rewardSoftCurrency = $reward['rewardSoftCurrency']; | ||
$softCurrency = GetCurrency($playerId, $gameData['softCurrencyId']); | ||
$softCurrency->amount += $rewardSoftCurrency; | ||
$softCurrency->update(); | ||
$updateCurrencies[] = $softCurrency; | ||
|
||
// Hard currency | ||
$rewardHardCurrency = $reward['rewardHardCurrency']; | ||
$hardCurrency = GetCurrency($playerId, $gameData['hardCurrencyId']); | ||
$hardCurrency->amount += $rewardHardCurrency; | ||
$hardCurrency->update(); | ||
$updateCurrencies[] = $hardCurrency; | ||
|
||
$wheelRewardItems = $reward['rewardItems']; | ||
$countRewardItems = count($wheelRewardItems); | ||
for ($i = 0; $i < $countRewardItems; ++$i) | ||
{ | ||
$rewardItem = $wheelRewardItems[$i]; | ||
$addItemsResult = AddItems($playerId, $rewardItem['id'], $rewardItem['amount']); | ||
if ($addItemsResult['success']) | ||
{ | ||
$rewards[] = CreateEmptyItem($i, $playerId, $rewardItem['id'], $rewardItem['amount']); | ||
|
||
$resultCreateItems = $addItemsResult['createItems']; | ||
$resultUpdateItems = $addItemsResult['updateItems']; | ||
$countCreateItems = count($resultCreateItems); | ||
$countUpdateItems = count($resultUpdateItems); | ||
for ($j = 0; $j < $countCreateItems; ++$j) | ||
{ | ||
$createItem = $resultCreateItems[$j]; | ||
$createItem->save(); | ||
HelperUnlockItem($playerId, $createItem->dataId); | ||
$createItems[] = $createItem; | ||
} | ||
for ($j = 0; $j < $countUpdateItems; ++$j) | ||
{ | ||
$updateItem = $resultUpdateItems[$j]; | ||
$updateItem->update(); | ||
$updateItems[] = $updateItem; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
$output['rewardItems'] = ItemCursorsToArray($rewardItems); | ||
$output['createItems'] = ItemCursorsToArray($createItems); | ||
$output['updateItems'] = ItemCursorsToArray($updateItems); | ||
$output['deleteItemIds'] = $deleteItemIds; | ||
$output['updateCurrencies'] = CursorsToArray($updateCurrencies); | ||
$output['rewardIndex'] = $rewardIndex; | ||
} | ||
echo json_encode($output); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
function GetAvailableIapPackageList() | ||
{ | ||
$list = array(); | ||
$gameData = \Base::instance()->get('GameData'); | ||
$iapPackages = $gameData['iapPackages']; | ||
foreach ($iapPackages as $key => $value) { | ||
$list[] = $key; | ||
} | ||
$output = array('error' => ''); | ||
$output['list'] = $list; | ||
echo json_encode($output); | ||
} | ||
|
||
function GetAvailableInGamePackageList() | ||
{ | ||
$list = array(); | ||
$gameData = \Base::instance()->get('GameData'); | ||
$inGamePackages = $gameData['inGamePackages']; | ||
foreach ($inGamePackages as $key => $value) { | ||
$list[] = $key; | ||
} | ||
$output = array('error' => ''); | ||
$output['list'] = $list; | ||
echo json_encode($output); | ||
} | ||
|
||
function OpenInGamePackage($inGamePackageDataId) | ||
{ | ||
$gameData = \Base::instance()->get('GameData'); | ||
$output = array('error' => ''); | ||
$player = GetPlayer(); | ||
$playerId = $player->id; | ||
|
||
$inGamePackage = $gameData['inGamePackages'][$inGamePackageDataId]; | ||
if (!$inGamePackage) { | ||
$output['error'] = 'ERROR_INVALID_IN_GAME_PACKAGE_DATA'; | ||
} else { | ||
$softCurrency = GetCurrency($playerId, $gameData['softCurrencyId']); | ||
$hardCurrency = GetCurrency($playerId, $gameData['hardCurrencyId']); | ||
|
||
$rewardItems = array(); | ||
$createItems = array(); | ||
$updateItems = array(); | ||
$deleteItemIds = array(); | ||
$updateCurrencies = array(); | ||
$requirementType = $inGamePackage['requirementType']; | ||
$price = $inGamePackage['price']; | ||
$rewardSoftCurrency = $inGamePackage['rewardSoftCurrency']; | ||
$rewardHardCurrency = $inGamePackage['rewardHardCurrency']; | ||
if ($requirementType == EInGamePackageRequirementType::SoftCurrency && $price > $softCurrency->amount) { | ||
$output['error'] = 'ERROR_NOT_ENOUGH_SOFT_CURRENCY'; | ||
} else if ($requirementType == EInGamePackageRequirementType::HardCurrency && $price > $hardCurrency->amount) { | ||
$output['error'] = 'ERROR_NOT_ENOUGH_HARD_CURRENCY'; | ||
} else { | ||
switch ($requirementType) | ||
{ | ||
case EInGamePackageRequirementType::SoftCurrency: | ||
$softCurrency->amount -= $price; | ||
break; | ||
case EInGamePackageRequirementType::HardCurrency: | ||
$hardCurrency->amount -= $price; | ||
break; | ||
} | ||
// Increase soft currency | ||
$softCurrency->amount += $rewardSoftCurrency; | ||
$softCurrency->update(); | ||
$updateCurrencies[] = $softCurrency; | ||
// Increase hard currency | ||
$hardCurrency->amount += $rewardHardCurrency; | ||
$hardCurrency->update(); | ||
$updateCurrencies[] = $hardCurrency; | ||
|
||
$countRewardItems = count($inGamePackage['rewardItems']); | ||
for ($i = 0; $i < $countRewardItems; ++$i) | ||
{ | ||
$rewardItem = $inGamePackage['rewardItems'][$i]; | ||
if (empty($rewardItem) || empty($rewardItem['id'])) { | ||
continue; | ||
} | ||
|
||
$addItemsResult = AddItems($playerId, $rewardItem['id'], $rewardItem['amount']); | ||
if ($addItemsResult['success']) | ||
{ | ||
$rewardItems[] = CreateEmptyItem($i, $playerId, $rewardItem['id'], $rewardItem['amount']); | ||
|
||
$resultCreateItems = $addItemsResult['createItems']; | ||
$resultUpdateItems = $addItemsResult['updateItems']; | ||
$countCreateItems = count($resultCreateItems); | ||
$countUpdateItems = count($resultUpdateItems); | ||
for ($j = 0; $j < $countCreateItems; ++$j) | ||
{ | ||
$createItem = $resultCreateItems[$j]; | ||
$createItem->save(); | ||
HelperUnlockItem($playerId, $createItem->dataId); | ||
$createItems[] = $createItem; | ||
} | ||
for ($j = 0; $j < $countUpdateItems; ++$j) | ||
{ | ||
$updateItem = $resultUpdateItems[$j]; | ||
$updateItem->update(); | ||
$updateItems[] = $updateItem; | ||
} | ||
} | ||
} | ||
$output['rewardItems'] = ItemCursorsToArray($rewardItems); | ||
$output['createItems'] = ItemCursorsToArray($createItems); | ||
$output['updateItems'] =ItemCursorsToArray($updateItems); | ||
$output['deleteItemIds'] = $deleteItemIds; | ||
$output['updateCurrencies'] = CursorsToArray($updateCurrencies); | ||
$output['rewardSoftCurrency'] = $rewardSoftCurrency; | ||
$output['rewardHardCurrency'] = $rewardHardCurrency; | ||
} | ||
} | ||
echo json_encode($output); | ||
} | ||
?> |
Oops, something went wrong.