This repository has been archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
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 #81 from Pluviolithic/refactor/issue-64/improve-co…
…mbat Closes #64
- Loading branch information
Showing
14 changed files
with
576 additions
and
470 deletions.
There are no files selected for viewing
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,38 @@ | ||
# Contributing to Horror Simulator | ||
Thanks for contributing to Horror Simulator! This guide has a few tips and guidelines to make contributing to the project as easy as possible. | ||
|
||
## Bug Reports | ||
Any bugs (or things that look like bugs) can be reported on the [GitHub issue tracker](https://github.com/pluviolithic/horror-simulator/issues) | ||
|
||
Make sure you check to see if someone has already reported your bug first! | ||
|
||
## Working on Horror Simulator | ||
To get started working on Horror Simulator, you'll need: | ||
* Git | ||
* [Wally](https://github.com/UpliftGames/wally) | ||
* [StyLua](https://github.com/JohnnyMorganz/StyLua) | ||
* [Selene](https://github.com/Kampfkarren/selene) | ||
|
||
The `setup` make target will automatically install and configure all of them via aftman. | ||
```sh | ||
git clone https://github.com/pluviolithic/horror-simulator/ | ||
cd horror-simulator | ||
make setup | ||
``` | ||
|
||
### Pull Requests | ||
Before starting a pull request, open an issue about the feature or bug. This helps us prevent duplicated and wasted effort. These issues are a great place to ask for help if you run into problems! | ||
|
||
Before you submit a new pull request, check: | ||
* Code Quality: Run [Selene](https://github.com/Kampfkarren/selene) on your code, no warnings allowed! | ||
* Code Style: Run [StyLua](https://github.com/JohnnyMorganz/StyLua) on your code so it's formatted to follow the Roblox Lua Style Guide | ||
|
||
### Code Style | ||
Try to match the existing code style! In short: | ||
|
||
* Tabs for indentation | ||
* Double quotes | ||
* One statement per line | ||
|
||
Use StyLua to automatically format your code to comply with the Roblox Lua Style Guide. | ||
You can run this tool manually from the commandline (`stylua -c src/`), or use one of StyLua's editor integrations. |
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,6 @@ | ||
setup: | ||
curl https://sh.rustup.rs -sSf | sh -s -- -y | ||
cargo install aftman | ||
aftman self-install | ||
aftman install --no-trust-check | ||
wally install |
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 |
---|---|---|
@@ -1 +1,26 @@ | ||
# horror-simulator | ||
# horror-simulator | ||
Generated by [Rojo](https://github.com/rojo-rbx/rojo) 7.3.0. | ||
|
||
## Getting Started | ||
To install the necessary tooling, use: | ||
```sh | ||
make setup | ||
``` | ||
|
||
To build the place from scratch, use: | ||
|
||
```sh | ||
rojo build -o "horror-simulator.rbxlx" | ||
``` | ||
|
||
Next, open `horror-simulator.rbxlx` in Roblox Studio and start the Rojo server: | ||
|
||
```sh | ||
rojo serve | ||
``` | ||
|
||
For more help, check out [the Rojo documentation](https://rojo.space/docs). | ||
|
||
## Contributing | ||
|
||
See [the contribution guide](CONTRIBUTING.md) before contributing! |
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 |
---|---|---|
@@ -1,31 +1,31 @@ | ||
{ | ||
"name": "horror-simulator", | ||
"tree": { | ||
"$className": "DataModel", | ||
"ReplicatedStorage": { | ||
"Common": { | ||
"$path": "src/shared", | ||
"lib": { | ||
"$className": "Folder", | ||
"$path": "./Packages" | ||
} | ||
} | ||
}, | ||
"ServerScriptService": { | ||
"Server": { | ||
"$path": "src/server", | ||
"lib": { | ||
"$className": "Folder", | ||
"$path": "./ServerPackages" | ||
} | ||
} | ||
}, | ||
"StarterPlayer": { | ||
"StarterPlayerScripts": { | ||
"Client": { | ||
"$path": "src/client" | ||
} | ||
} | ||
"name": "horror-simulator", | ||
"tree": { | ||
"$className": "DataModel", | ||
"ReplicatedStorage": { | ||
"Common": { | ||
"$path": "src/shared", | ||
"lib": { | ||
"$className": "Folder", | ||
"$path": "./Packages" | ||
} | ||
} | ||
}, | ||
"ServerScriptService": { | ||
"Server": { | ||
"$path": "src/server", | ||
"lib": { | ||
"$className": "Folder", | ||
"$path": "./ServerPackages" | ||
} | ||
} | ||
}, | ||
"StarterPlayer": { | ||
"StarterPlayerScripts": { | ||
"Client": { | ||
"$path": "src/client" | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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,49 @@ | ||
local ReplicatedStorage = game:GetService "ReplicatedStorage" | ||
local ServerScriptService = game:GetService "ServerScriptService" | ||
|
||
local store = require(ServerScriptService.Server.State.Store) | ||
local actions = require(ServerScriptService.Server.State.Actions) | ||
local selectors = require(ReplicatedStorage.Common.State.selectors) | ||
local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils) | ||
|
||
local weapons = ReplicatedStorage.Weapons | ||
|
||
local function canAttack(player, enemy, info) | ||
if not enemy:IsDescendantOf(game) then | ||
return false | ||
end | ||
|
||
local rootPart = if enemy.Humanoid.RootPart then enemy.Humanoid.RootPart else enemy:FindFirstChild "RootPart" | ||
local fightRange = enemy.Configuration.FightRange.Value | ||
|
||
return info.HealthValue.Value > 0 | ||
and selectors.isPlayerLoaded(store:getState(), player.Name) | ||
and selectors.getCurrentTarget(store:getState(), player.Name) == enemy | ||
and player:DistanceFromCharacter(rootPart.Position) <= fightRange + 10 | ||
end | ||
|
||
return function(player, enemy, info, janitor) | ||
local weaponName = selectors.getEquippedWeapon(store:getState(), player.Name) | ||
local damageMultiplier = if weaponName == "Fists" then 1 else weapons[weaponName].Damage.Value | ||
|
||
store:dispatch(actions.combatBegan(player.Name)) | ||
|
||
if weaponName ~= "Fists" then | ||
local weaponAccessory = weapons[weaponName]:Clone() | ||
player.Character.Humanoid:AddAccessory(weaponAccessory) | ||
janitor:Add(weaponAccessory) | ||
end | ||
|
||
task.spawn(function() | ||
while canAttack(player, enemy, info) do | ||
local damageToDeal = math.clamp( | ||
selectors.getStat(store:getState(), player.Name, "Strength") * damageMultiplier, | ||
0, | ||
info.HealthValue.Value | ||
) | ||
info.DamageDealtByPlayer[player] = (info.DamageDealtByPlayer[player] or 0) + damageToDeal | ||
info.HealthValue.Value -= damageToDeal | ||
task.wait(animationUtilities.getPlayerAttackSpeed(player)) | ||
end | ||
end) | ||
end |
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,44 @@ | ||
local ReplicatedStorage = game:GetService "ReplicatedStorage" | ||
local CollectionService = game:GetService "CollectionService" | ||
local ServerScriptService = game:GetService "ServerScriptService" | ||
|
||
local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value | ||
local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value | ||
|
||
local store = require(ServerScriptService.Server.State.Store) | ||
local actions = require(ServerScriptService.Server.State.Actions) | ||
local selectors = require(ReplicatedStorage.Common.State.selectors) | ||
|
||
return function(enemy, info, janitor) | ||
if info.DamageActive then | ||
return | ||
end | ||
info.DamageActive = true | ||
|
||
local attackDelay = if CollectionService:HasTag(enemy, "Boss") then bossAttackSpeed else enemyAttackSpeed | ||
local damagePlayers = true | ||
|
||
task.spawn(function() | ||
while damagePlayers do | ||
for _, player in info.EngagedPlayers do | ||
local fearMeterGoal = math.min( | ||
selectors.getStat(store:getState(), player.Name, "CurrentFearMeter") | ||
+ enemy.Configuration.Damage.Value, | ||
selectors.getStat(store:getState(), player.Name, "MaxFearMeter") | ||
) | ||
local fearMeterAddendum = fearMeterGoal | ||
- selectors.getStat(store:getState(), player.Name, "CurrentFearMeter") | ||
|
||
if fearMeterAddendum ~= 0 then | ||
store:dispatch(actions.incrementPlayerStat(player.Name, "CurrentFearMeter", fearMeterAddendum)) | ||
end | ||
end | ||
task.wait(attackDelay) | ||
end | ||
end) | ||
|
||
janitor:Add(function() | ||
info.DamageActive = nil | ||
damagePlayers = false | ||
end, true) | ||
end |
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,42 @@ | ||
local ReplicatedStorage = game:GetService "ReplicatedStorage" | ||
local CollectionService = game:GetService "CollectionService" | ||
|
||
local bossAttackSpeed = ReplicatedStorage.Config.Combat.BossAttackSpeed.Value | ||
local enemyAttackSpeed = ReplicatedStorage.Config.Combat.EnemyAttackSpeed.Value | ||
|
||
local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils) | ||
|
||
return function(enemy, info, janitor) | ||
if info.AnimationsActive then | ||
return | ||
end | ||
info.AnimationsActive = true | ||
|
||
local attackDelay = if CollectionService:HasTag(enemy, "Boss") then bossAttackSpeed else enemyAttackSpeed | ||
local runAnimations = true | ||
|
||
local animationInstances = | ||
animationUtilities.filterAndSortAnimationInstances(enemy.Configuration.AttackAnims:GetChildren()) | ||
local currentIndex, animationTrack, animation = 0, nil, nil | ||
|
||
task.spawn(function() | ||
while runAnimations do | ||
currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex) | ||
animationTrack = enemy.Humanoid:LoadAnimation(animation) | ||
animationTrack.Priority = Enum.AnimationPriority.Action | ||
|
||
animationTrack:Play() | ||
animationTrack.Stopped:Wait() | ||
animationTrack:Destroy() | ||
task.wait(attackDelay) | ||
end | ||
end) | ||
|
||
janitor:Add(function() | ||
runAnimations = false | ||
info.AnimationsActive = nil | ||
if animationTrack.IsPlaying then | ||
animationTrack:Stop() | ||
end | ||
end, true) | ||
end |
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,37 @@ | ||
local ReplicatedStorage = game:GetService "ReplicatedStorage" | ||
local ServerScriptService = game:GetService "ServerScriptService" | ||
|
||
local combatAnimations = ReplicatedStorage.CombatAnimations | ||
|
||
local store = require(ServerScriptService.Server.State.Store) | ||
local selectors = require(ReplicatedStorage.Common.State.selectors) | ||
local animationUtilities = require(ReplicatedStorage.Common.Utils.AnimationUtils) | ||
|
||
return function(player, janitor) | ||
local runAnimations = true | ||
|
||
local currentIndex, animationTrack, animation = 0, nil, nil | ||
local animationInstances = animationUtilities.filterAndSortAnimationInstances( | ||
combatAnimations[selectors.getEquippedWeapon(store:getState(), player.Name)]:GetChildren() | ||
) | ||
|
||
task.spawn(function() | ||
while runAnimations do | ||
currentIndex, animation = animationUtilities.getNextIndexAndAnimationTrack(animationInstances, currentIndex) | ||
animationTrack = player.Character.Humanoid:LoadAnimation(animation) | ||
animationTrack.Priority = Enum.AnimationPriority.Action | ||
|
||
animationTrack:Play() | ||
animationTrack.Stopped:Wait() | ||
animationTrack:Destroy() | ||
task.wait(animationUtilities.getPlayerAttackSpeed(player)) | ||
end | ||
end) | ||
|
||
janitor:Add(function() | ||
runAnimations = false | ||
if animationTrack.IsPlaying then | ||
animationTrack:Stop() | ||
end | ||
end, true) | ||
end |
Oops, something went wrong.