-
Notifications
You must be signed in to change notification settings - Fork 5
Fixes #49: Character cannot have two equal items #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.25") | ||
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.31") | ||
|
||
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.14.0") | ||
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler-sjs06" % "0.16.0") |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,7 @@ abstract class Weapon extends EquipmentItem { | |
def damage: Int | ||
} | ||
|
||
case class Knife(name: String, | ||
damage: Int = 50) extends Weapon { | ||
class Knife(private val _name: String, private val _damage: Int) extends Weapon { | ||
|
||
val cooldown = 200 | ||
val missCooldown = 100 | ||
|
@@ -37,4 +36,14 @@ case class Knife(name: String, | |
|
||
override val requires: Set[Capability] = Set(ManipulatorCapability) | ||
|
||
override def damage: Int = _damage | ||
|
||
/** | ||
* Name of equipment item. | ||
*/ | ||
override def name: String = _name | ||
} | ||
|
||
object Knife { | ||
def apply(name: String, damage: Int = 50) = new Knife(name, damage) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly, I dislike the approach taken. Now we'll be required to be very careful when declaring our item classes to not hit the same issue with any of them. There's an alternate route with marking our items with identifiers (the same as we already use for actors and factions). @ttldtor, what do you think about this alternative? Would it be worse? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ForNeVeR I don't see any faction id: |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,10 +2,11 @@ package ru.org.codingteam.keter.scenes.inventory | |
|
||
import ru.org.codingteam.keter.game.objects.Inventory | ||
import ru.org.codingteam.keter.game.objects.equipment.EquipmentCategory._ | ||
import ru.org.codingteam.keter.game.objects.equipment.{EquipmentCategory, EquipmentItem} | ||
import ru.org.codingteam.keter.game.objects.equipment.{Capability, EquipmentCategory, EquipmentItem} | ||
import ru.org.codingteam.keter.ui.viewmodels.{ItemsViewModel, StaticTextViewModel} | ||
import ru.org.codingteam.keter.util.VectorMap | ||
|
||
import scala.collection.mutable | ||
import scala.concurrent.Promise | ||
|
||
class InventoryViewModel(var inventory: Inventory) { | ||
|
@@ -33,20 +34,31 @@ class InventoryViewModel(var inventory: Inventory) { | |
|
||
val currentFolderItems = new ItemsViewModel[EquipmentItem](toVectorMap(inventory.allEquipment.toSeq)) { | ||
|
||
def canEquip(item: EquipmentItem): Boolean = { | ||
val inventoryProvidedCapabilities = inventory.body.foldLeft(mutable.MultiSet[Capability]())(_ ++= _.provides) | ||
val inventoryRequiredCapabilities = inventory.equipment.foldLeft(mutable.MultiSet[Capability]())(_ ++= _.requires) | ||
|
||
inventoryProvidedCapabilities --= inventoryRequiredCapabilities | ||
(item.requires & inventoryProvidedCapabilities.toSet) == item.requires | ||
} | ||
|
||
def equipped(item: EquipmentItem): Boolean = { | ||
inventory.equipment.contains(item) | ||
} | ||
|
||
def toggleSelected() = { | ||
def toggleSelected(): Unit = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add a test for the new behavior of this method? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ForNeVeR ok |
||
selectedItem foreach { item => | ||
var backpack = inventory.backpack | ||
var equipment = inventory.equipment | ||
|
||
if (equipped(item)) { | ||
equipment -= item | ||
backpack += item | ||
} else { | ||
} else if (canEquip(item)) { | ||
backpack -= item | ||
equipment += item | ||
} else { | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to return the missing capabilities from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ForNeVeR ok |
||
} | ||
|
||
inventory = inventory.copy(backpack = backpack, equipment = equipment) | ||
|
@@ -58,6 +70,6 @@ class InventoryViewModel(var inventory: Inventory) { | |
|
||
private def toVectorMap(items: Seq[EquipmentItem]): VectorMap[EquipmentItem, String] = { | ||
val itemsWithNames = items.map(equipment => (equipment, equipment.name)) | ||
VectorMap(itemsWithNames.toSeq: _*) | ||
VectorMap(itemsWithNames: _*) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ru.org.codingteam.keter.game.objects | ||
|
||
import ru.org.codingteam.keter.game.objects.equipment.items.Knife | ||
import utest._ | ||
|
||
import scala.collection.MultiSet | ||
|
||
object InventoryTest extends TestSuite { | ||
val tests = Tests { | ||
test("shouldSetTwoKnifes") { | ||
val i = Inventory(Set(), Set(Knife("Knife")), Set(Knife("Knife"))) | ||
println(i.allEquipment) | ||
assert(i.allEquipment.size == 2) | ||
} | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.